<html lang="zh-cn"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>php中正则表达式详解 - helloworldlee - 博客园</title>
    <link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=m_FXmwz3wxZoecUwNEK23PAzc-j9vbX_C6MblJ5ouMc1">
    <link id="MainCss" type="text/css" rel="stylesheet" href="/skins/BlackLowKey/bundle-BlackLowKey.css?v=B7-m2NxlKbJ6xN_kGRXgbaLp9_4SHPK1jC_DQ8UbhqA1">
    <link id="mobile-style" media="only screen and (max-width: 768px)" type="text/css" rel="stylesheet" href="/skins/BlackLowKey/bundle-BlackLowKey-mobile.css?v=hM_4ic4i3O5wKXUjikUYwUGh6o9_4est1wSubdkIKhE1">
    <link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/hellohell/rss">
    <link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/hellohell/rsd.xml">
    <link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/hellohell/wlwmanifest.xml">
    <script async="" src="https://www.google-analytics.com/analytics.js"></script><script src="//common.cnblogs.com/script/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">var currentBlogApp = 'hellohell', cb_enable_mathjax=false;var isLogined=false;</script>
    <script src="/bundles/blog-common.js?v=E1-LyrzANB2jbN9omtnpOHx3eU0Kt3DyislfhU0b5p81" type="text/javascript"></script>
</head>
<body>
<a name="top"></a>

<!--done-->
<div id="home">
    <div id="header">
        <div id="blogTitle">
            <a id="lnkBlogLogo" href="http://www.cnblogs.com/hellohell/"><img id="blogLogo" src="/Skins/custom/images/logo.gif" alt="返回主页"></a>

            <!--done-->
            <h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/hellohell/">hello world</a></h1>
            <h2>阅读的意义就在于引发我们的思考，不动脑筋的阅读，只能称之为消遣。</h2>




        </div><!--end: blogTitle 博客的标题和副标题 -->
        <div id="navigator">

            <ul id="navList">
                <li><a id="blog_nav_sitehome" class="menu" href="http://www.cnblogs.com/">博客园</a></li>
                <li><a id="blog_nav_myhome" class="menu" href="http://www.cnblogs.com/hellohell/">首页</a></li>
                <li><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li>
                <li><a id="blog_nav_contact" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/helloworldlee">联系</a></li>
                <li><a id="blog_nav_rss" class="menu" href="http://www.cnblogs.com/hellohell/rss">订阅</a>
                    <!--<a id="blog_nav_rss_image" class="aHeaderXML" href="http://www.cnblogs.com/hellohell/rss"><img src="//www.cnblogs.com/images/xml.gif" alt="订阅" /></a>--></li>
                <li><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">管理</a></li>
            </ul>
            <div class="blogStats">

                <div id="blog_stats">
                    <span id="stats_post_count">随笔 - 39&nbsp; </span>
                    <span id="stats_article_count">文章 - 0&nbsp; </span>
                    <span id="stats-comment_count">评论 - 1</span>
                </div>

            </div><!--end: blogStats -->
        </div><!--end: navigator 博客导航栏 -->
    </div><!--end: header 头部 -->

    <div id="main">
        <div id="mainContent">
            <div class="forFlow">

                <div id="post_detail">
                    <!--done-->
                    <div id="topics">
                        <div class="post">
                            <h1 class="postTitle">
                                <a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/hellohell/p/5718319.html">php中正则表达式详解</a>
                            </h1>
                            <div class="clear"></div>
                            <div class="postBody">
                                <div id="cnblogs_post_body"><h1 id="概述">概述</h1>
                                    <p>正则表达式是一种描述字符串结果的语法规则，是一个特定的格式化模式，可以匹配、替换、截取匹配的字符串。常用的语言基本上都有正则表达式，如JavaScript、java等。其实，只有了解一种语言的正则使用，其他语言的正则使用起来，就相对简单些。文本主要围绕解决下面问题展开。</p>
                                    <ul>
                                        <li>有哪些常用的转义字符</li>
                                        <li>什么是限定符与定位符</li>
                                        <li>什么是单词定位符</li>
                                        <li>特殊字符有哪些</li>
                                        <li>什么是逆向引用以及怎样使用逆向引用</li>
                                        <li>匹配模式</li>
                                        <li>php中怎样使用正则表达式</li>
                                        <li>php中哪些方面需要用到正则</li>
                                        <li>怎样进行邮箱匹配，url匹配，手机匹配</li>
                                        <li>怎样使用正则替换字符串中某些字符</li>
                                        <li>贪婪匹配与惰性匹配区别</li>
                                        <li>正则表达式之回溯与固态分组</li>
                                        <li>正则优缺点有哪些</li>
                                    </ul>
                                    <h1 id="正则表达式的基本知识汇总"><a name="t1"></a>正则表达式的基本知识汇总</h1>
                                    <h1 id="行定位符与"><a name="t2"></a>行定位符（^与$）</h1>
                                    <p>行定位符是用来描述字符串的边界。<code>“$”</code>表示行结尾<code>“^”</code>表示行开始如<code>"^de"</code>，表示以de开头的字符串&nbsp;<code>"de$"</code>,表示以de结尾的字符串。</p>
                                    <h2 id="单词定界符"><a name="t3"></a>单词定界符</h2>
                                    <p>我们在查找的一个单词的时候，如an是否在一个字符串”gril and body”中存在，很明显如果匹配的话，an肯定是可以匹配字符串“gril and body”匹配到，怎样才能让其匹配单词，而不是单词的一部分呢？这时候，我们可以是哟个单词定界符\b。&nbsp;<br>\ban\b 去匹配”gril and body”的话，就会提示匹配不到。&nbsp;<br>当然还有一个大写的\B，它的意思，和\b正好相反，它匹配的字符串不能使一个完整的单词，而是其他单词或字符串中的一部分。如\Ban\B。</p>
                                    <h2 id="选择字符-表示或"><a name="t4"></a>选择字符(|) ，表示或</h2>
                                    <p>选择字符表示或的意思。如Aa|aA，表示Aa或者是aA的意思。注意使用”[]”与”|”的区别，在于”[]”只能匹配单个字符，而”|”可以匹配任意长度的字符串。在使用”[]”的时候，往往配合连接字符”-“一起使用，如[a-d],代表a或b或c或d。</p>
                                    <h2 id="排除字符排除操作"><a name="t5"></a>排除字符，排除操作</h2>
                                    <p>正则表达式提供了”^”来表示排除不符合的字符，^一般放在[]中。如[^1-5]，该字符不是1~5之间的数字。</p>
                                    <h2 id="限定符nm"><a name="t6"></a>限定符(？*+{n，m})</h2>
                                    <p>限定符主要是用来限定每个字符串出现的次数。</p>
                                    <table>
                                        <thead>
                                        <tr><th>限定字符</th><th align="center">含义</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>？</td>
                                            <td align="center">零次或一次</td>

                                        </tr>
                                        <tr>
                                            <td>*</td>
                                            <td align="center">零次或多次</td>

                                        </tr>
                                        <tr>
                                            <td>+</td>
                                            <td align="center">一次或多次</td>

                                        </tr>
                                        <tr>
                                            <td>{n}</td>
                                            <td align="center">n次</td>

                                        </tr>
                                        <tr>
                                            <td>{n,}</td>
                                            <td align="center">至少n次</td>

                                        </tr>
                                        <tr>
                                            <td>{n,m}</td>
                                            <td align="center">n到m次</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <p>如(D+)表示一个或多个D</p>
                                    <h2 id="点号操作符"><a name="t7"></a>点号操作符</h2>
                                    <p>匹配任意一个字符（不包含换行符）</p>
                                    <h2 id="表达式中的反斜杠"><a name="t8"></a>表达式中的反斜杠(<code>\</code>)</h2>
                                    <p>表达式中的反斜杠有多重意义，如转义、指定预定义的字符集、定义断言、显示不打印的字符。</p>
                                    <h3 id="转义字符"><a name="t9"></a>转义字符</h3>
                                    <p>转义字符主要是将一些特殊字符转为普通字符。而这些常用特殊字符有”.”，”?”、”\”等。</p>
                                    <h3 id="指定预定义的字符集"><a name="t10"></a>指定预定义的字符集</h3>
                                    <table>
                                        <thead>
                                        <tr><th>字符</th><th align="center">含义</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>\d</td>
                                            <td align="center">任意一个十进制数字[0-9]</td>

                                        </tr>
                                        <tr>
                                            <td>\D</td>
                                            <td align="center">任意一个非十进制数字</td>

                                        </tr>
                                        <tr>
                                            <td>\s</td>
                                            <td align="center">任意一个空白字符(空格、换行符、换页符、回车符、字表符)</td>

                                        </tr>
                                        <tr>
                                            <td>\S</td>
                                            <td align="center">任意一个非空白字符</td>

                                        </tr>
                                        <tr>
                                            <td>\w</td>
                                            <td align="center">任意一个单词字符</td>

                                        </tr>
                                        <tr>
                                            <td>\W</td>
                                            <td align="center">任意个非单词字符</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <p>###显示不可打印的字符</p>
                                    <table>
                                        <thead>
                                        <tr><th>字符</th><th align="center">含义</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>\a</td>
                                            <td align="center">报警</td>

                                        </tr>
                                        <tr>
                                            <td>\b</td>
                                            <td align="center">退格</td>

                                        </tr>
                                        <tr>
                                            <td>\f</td>
                                            <td align="center">换页</td>

                                        </tr>
                                        <tr>
                                            <td>\n</td>
                                            <td align="center">换行</td>

                                        </tr>
                                        <tr>
                                            <td>\r</td>
                                            <td align="center">回车</td>

                                        </tr>
                                        <tr>
                                            <td>\t</td>
                                            <td align="center">字表符</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h2 id="括号字符"><a name="t11"></a>括号字符()</h2>
                                    <p>在正则表达式中小括号的作用主要有:</p>
                                    <ul>
                                        <li>改变限定符如（|、* 、^)的作用范围&nbsp;<br>如(my|your)baby，如果没有”()”，|将匹配的是要么是my，要么是yourbaby,有了小括号，匹配的就是mybaby或yourbaby。</li>
                                        <li>进行分组，便于反向引用</li>

                                    </ul>
                                    <h2 id="反向引用"><a name="t12"></a>反向引用</h2>
                                    <p>反向引用，就是依靠子表达式的”记忆”功能，匹配连续出现的字串或是字符。如(dqs)(pps)\1\2，表示匹配字符串dqsppsdqspps。在下面php应用中，我将详细展开学习反向引用。</p>
                                    <h2 id="模式修饰符"><a name="t13"></a>模式修饰符</h2>
                                    <p>模式修饰符的作用是设定模式，也就是正则表达式如何解释。php中主要模式如下表：</p>
                                    <table>
                                        <thead>
                                        <tr><th>修饰符</th><th align="center">说明</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>i</td>
                                            <td align="center">忽略大小写</td>

                                        </tr>
                                        <tr>
                                            <td>m</td>
                                            <td align="center">多文本模式</td>

                                        </tr>
                                        <tr>
                                            <td>s</td>
                                            <td align="center">单行文本模式</td>

                                        </tr>
                                        <tr>
                                            <td>x</td>
                                            <td align="center">忽略空白字符</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h1 id="正则表达式在php中应用"><a name="t14"></a>正则表达式在php中应用</h1>
                                    <h2 id="php中字符串匹配"><a name="t15"></a>php中字符串匹配</h2>
                                    <p>所谓的字符串匹配，言外之意就是判断一个字符串中，是否包含或是等于另一个字符串。如果不使用正则，我们可以使用php中提供了很多方法进行这样的判断。</p>
                                    <h3 id="不使用正则匹配"><a name="t16"></a>不使用正则匹配</h3>
                                    <ul>
                                        <li>strstr函数&nbsp;<br>string strstr ( string&nbsp;<span class="MathJax_Preview"><span class="MathJax_Preview"><span class="MathJax"><span id="MathJax-Span-1" class="math"><span id="MathJax-Span-2" class="mrow"><span id="MathJax-Span-3" class="mi">h<span id="MathJax-Span-4" class="mi">a<span id="MathJax-Span-5" class="mi">y<span id="MathJax-Span-6" class="mi">s<span id="MathJax-Span-7" class="mi">t<span id="MathJax-Span-8" class="mi">a<span id="MathJax-Span-9" class="mi">c<span id="MathJax-Span-10" class="mi">k<span id="MathJax-Span-11" class="mo">,<span id="MathJax-Span-12" class="mi">m<span id="MathJax-Span-13" class="mi">i<span id="MathJax-Span-14" class="mi">x<span id="MathJax-Span-15" class="mi">e<span id="MathJax-Span-16" class="mi">d</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>needle [, bool $before_needle = false ])&nbsp;<br></span></span></span>
                                            <ul>
                                                <li>注1：<span class="MathJax_Preview"><span id="MathJax-Element-3-Frame" class="MathJax"><span id="MathJax-Span-17" class="math"><span id="MathJax-Span-18" class="mrow"><span id="MathJax-Span-19" class="mi">h<span id="MathJax-Span-20" class="mi">a<span id="MathJax-Span-21" class="mi">y<span id="MathJax-Span-22" class="mi">s<span id="MathJax-Span-23" class="mi">t<span id="MathJax-Span-24" class="mi">a<span id="MathJax-Span-25" class="mi">c<span id="MathJax-Span-26" class="mi">k<span id="MathJax-Span-27" class="texatom"><span id="MathJax-Span-28" class="mrow"><span id="MathJax-Span-29" class="mo">是<span id="MathJax-Span-30" class="texatom"><span id="MathJax-Span-31" class="mrow"><span id="MathJax-Span-32" class="mo">当<span id="MathJax-Span-33" class="texatom"><span id="MathJax-Span-34" class="mrow"><span id="MathJax-Span-35" class="mo">事<span id="MathJax-Span-36" class="texatom"><span id="MathJax-Span-37" class="mrow"><span id="MathJax-Span-38" class="mo">字<span id="MathJax-Span-39" class="texatom"><span id="MathJax-Span-40" class="mrow"><span id="MathJax-Span-41" class="mo">符<span id="MathJax-Span-42" class="texatom"><span id="MathJax-Span-43" class="mrow"><span id="MathJax-Span-44" class="mo">串<span id="MathJax-Span-45" class="texatom"><span id="MathJax-Span-46" class="mrow"><span id="MathJax-Span-47" class="mo">，</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>needle是被查找的字符串。该函数区分大小写。</span></span></li>
                                                <li>注2：返回值是从needle开始到最后。</li>
                                                <li>注3：关于$needle，如果不是字符串，被当作整形来作为字符的序号来使用。</li>
                                                <li>注4：before_needle若为true,则返回前东西。</li>

                                            </ul>

                                        </li>
                                        <li>stristr函数与strstr函数相同，只是它不区分大小写</li>
                                        <li>strpo函数&nbsp;<br>int strpos ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-4-Frame" class="MathJax"><span id="MathJax-Span-48" class="math"><span id="MathJax-Span-49" class="mrow"><span id="MathJax-Span-50" class="mi">h<span id="MathJax-Span-51" class="mi">a<span id="MathJax-Span-52" class="mi">y<span id="MathJax-Span-53" class="mi">s<span id="MathJax-Span-54" class="mi">t<span id="MathJax-Span-55" class="mi">a<span id="MathJax-Span-56" class="mi">c<span id="MathJax-Span-57" class="mi">k<span id="MathJax-Span-58" class="mo">,<span id="MathJax-Span-59" class="mi">m<span id="MathJax-Span-60" class="mi">i<span id="MathJax-Span-61" class="mi">x<span id="MathJax-Span-62" class="mi">e<span id="MathJax-Span-63" class="mi">d</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>needle [, int $offset = 0 ] )&nbsp;<br>注1：可选的 offset 参数可以用来指定从 haystack 中的哪一个字符开始查找。返回的数字位置是相对于 haystack 的起始位置而言的。</span></span></li>
                                        <li>stripos -查找字符串<strong>首次出现</strong>的位置（<strong>不区分大小</strong>定）</li>
                                        <li>strrpos -计算指定字符串在目标字符串中<strong>最后一次出现</strong>的位置</li>
                                        <li>strripos -计算指定字符串在目标字符串中<strong>最后一次出现</strong>的位置（<strong>不区分大小写</strong>）</li>

                                    </ul>
                                    <h3 id="使用正则进行匹配"><a name="t17"></a>使用正则进行匹配</h3>
                                    <p>在php中，提供了preg_math()和preg_match_all函数进行正则匹配。关于这两个函数原型如下：</p>
                                    <pre name="code" class="prettyprint"><code class="hljs mel has-numbering"><span class="hljs-keyword"><br>int preg_match|preg_match_all ( <span class="hljs-keyword">string <span class="hljs-variable">$pattern , <span class="hljs-keyword">string <span class="hljs-variable">$subject [, array &amp;<span class="hljs-variable">$matches [, <span class="hljs-keyword">int <span class="hljs-variable">$flags = <span class="hljs-number">0 [, <span class="hljs-keyword">int <span class="hljs-variable">$offset = <span class="hljs-number">0 ]]] )</span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <p>搜索subject与pattern给定的正则表达式的一个匹配.&nbsp;<br>pattern:要搜索的模式，字符串类型。&nbsp;<br>subject :输入字符串。&nbsp;<br>matches:如果提供了参数matches，它将被填充为搜索结果。&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-5-Frame" class="MathJax"><span id="MathJax-Span-64" class="math"><span id="MathJax-Span-65" class="mrow"><span id="MathJax-Span-66" class="mi">m<span id="MathJax-Span-67" class="mi">a<span id="MathJax-Span-68" class="mi">t<span id="MathJax-Span-69" class="mi">c<span id="MathJax-Span-70" class="mi">h<span id="MathJax-Span-71" class="mi">e<span id="MathJax-Span-72" class="mi">s<span id="MathJax-Span-73" class="mo">[<span id="MathJax-Span-74" class="mn">0<span id="MathJax-Span-75" class="mo">]<span id="MathJax-Span-76" class="texatom"><span id="MathJax-Span-77" class="mrow"><span id="MathJax-Span-78" class="mo">将<span id="MathJax-Span-79" class="texatom"><span id="MathJax-Span-80" class="mrow"><span id="MathJax-Span-81" class="mo">包<span id="MathJax-Span-82" class="texatom"><span id="MathJax-Span-83" class="mrow"><span id="MathJax-Span-84" class="mo">含<span id="MathJax-Span-85" class="texatom"><span id="MathJax-Span-86" class="mrow"><span id="MathJax-Span-87" class="mo">完<span id="MathJax-Span-88" class="texatom"><span id="MathJax-Span-89" class="mrow"><span id="MathJax-Span-90" class="mo">整<span id="MathJax-Span-91" class="texatom"><span id="MathJax-Span-92" class="mrow"><span id="MathJax-Span-93" class="mo">模<span id="MathJax-Span-94" class="texatom"><span id="MathJax-Span-95" class="mrow"><span id="MathJax-Span-96" class="mo">式<span id="MathJax-Span-97" class="texatom"><span id="MathJax-Span-98" class="mrow"><span id="MathJax-Span-99" class="mo">匹<span id="MathJax-Span-100" class="texatom"><span id="MathJax-Span-101" class="mrow"><span id="MathJax-Span-102" class="mo">配<span id="MathJax-Span-103" class="texatom"><span id="MathJax-Span-104" class="mrow"><span id="MathJax-Span-105" class="mo">到<span id="MathJax-Span-106" class="texatom"><span id="MathJax-Span-107" class="mrow"><span id="MathJax-Span-108" class="mo">的<span id="MathJax-Span-109" class="texatom"><span id="MathJax-Span-110" class="mrow"><span id="MathJax-Span-111" class="mo">文<span id="MathJax-Span-112" class="texatom"><span id="MathJax-Span-113" class="mrow"><span id="MathJax-Span-114" class="mo">本<span id="MathJax-Span-115" class="texatom"><span id="MathJax-Span-116" class="mrow"><span id="MathJax-Span-117" class="mo">，</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>matches[1]将包含第一个捕获子组匹配到的文本，以此类推。&nbsp;<br>flags:flags可以被设置为以下标记值：PREG_OFFSET_CAPTURE 如果传递了这个标记，对于每一个出现的匹配返回时会附加字符串偏移量(相对于目标字符串的)。 注意：这会改变填充到matches参数的数组，使其每个元素成为一个由 第0个元素是匹配到的字符串，第1个元素是该匹配字符串 在目标字符串subject中的偏移量。&nbsp;<br>offset:通常，搜索从目标字符串的开始位置开始。可选参数 offset 用于 指定从目标字符串的某个未知开始搜索(单位是字节)。&nbsp;<br>返回值：preg_match()返回 pattern 的匹配次数。 它的值将是0次（不匹配）或1次，因为 preg_match()在第一次匹配后 将会停止搜索。 preg_match_all()不同于此，它会一直搜索subject直到到达结尾。 如果发生错误 preg_match()返回 FALSE。</span></span></p>
                                    <h3 id="实例"><a name="t18"></a>实例</h3>
                                    <ul>
                                        <li>实例1&nbsp;<br>判断字符串”<a href="http://blog.csdn.net/hsd2012">http://blog.csdn.net/hsd2012</a>“中是否包含csdn?&nbsp;<br>解法一（不适用正则）：&nbsp;<br>如果不适用正则，我们使用strstr或者strpos中任意一个都可以，在此，我将使用strstr函数，代码如下：</li>

                                    </ul>
                                    <pre name="code" class="prettyprint"><code class="hljs php has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012';
<span class="hljs-function"><span class="hljs-keyword">function <span class="hljs-title">checkStr1<span class="hljs-params">(<span class="hljs-variable">$str,<span class="hljs-variable">$str2)
{
    <span class="hljs-keyword">return strstr1(<span class="hljs-variable">$str,<span class="hljs-variable">$str2)?<span class="hljs-keyword">true:<span class="hljs-keyword">false;
}
<span class="hljs-keyword">echo checkStr(<span class="hljs-variable">$str,<span class="hljs-string">'csdn');</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <p>解法二：使用正则&nbsp;<br>因为我们只需要判断是否存在即可，所以选择preg_match。</p>
                                    <pre name="code" class="prettyprint"><code class="hljs php has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/csdn/';
<span class="hljs-function"><span class="hljs-keyword">function <span class="hljs-title">checkStr2<span class="hljs-params">(<span class="hljs-variable">$str,<span class="hljs-variable">$str2)
{
    <span class="hljs-keyword">return preg_match(<span class="hljs-variable">$str2,<span class="hljs-variable">$str)?<span class="hljs-keyword">true:<span class="hljs-keyword">false;
}
<span class="hljs-keyword">echo checkStr2(<span class="hljs-variable">$str,<span class="hljs-variable">$pattern);</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <ul>
                                        <li>实例2（考察<strong>单词定界符</strong>）&nbsp;<br>判断字符串”I am a good boy”中是否包含单词go&nbsp;<br>首先判断是单词，而不是字符串，因此比较的时候，需要比较是否包含’ go ‘，即在字符串go前后有一个空格。&nbsp;<br>解析：如果使用非正则比较，只需要调用上面的checkStr1()函数即可，注意，第二个参数前后要加一个空格,即’ go ‘。如果使用正则，&nbsp;<br>我们可以考虑使用单词定界符\b，那么$pattern=’/\bgo\b/’;然后调用checkStr2函数即可.</li>
                                        <li>例3（考察<strong>反向引用</strong>)&nbsp;<br>判断字符串”I am a good boy”中是否包含3个相同的字母&nbsp;<br>解析：此时，如果我们不使用正则，将会很难判断，因为字母太多了，我们不可能去将所有字母分别与该字符串比较，那样工作量也比较大。这时候涉及到了正在的反向引用。在php正则表达式中，通过\n，来表示第n次匹配到的结果。如\5代表第五次匹配到的结果。那么本题的<code>$pattern='/(\w).*\1.*\1/';</code>&nbsp;<br>主要注意的是，在使用反向匹配的时候都需要使用(),反向匹配时，匹配()里面出现的字符或字符串。</li>

                                    </ul>
                                    <h2 id="php中字符串替换"><a name="t19"></a>php中字符串替换</h2>
                                    <h3 id="不使用正则"><a name="t20"></a>不使用正则</h3>
                                    <p>php中当替换字符串的时候，如果不适用正则，我们通常使用substr、mb_substr、str_replace、substr_replace关于这几个函数区别如下表。</p>
                                    <table>
                                        <thead>
                                        <tr><th>函数符</th><th align="center">功能</th><th align="center">描述</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>str_replace(find,replace,string,count)</td>
                                            <td align="center">使用一个字符串替换字符串中的另一些字符。</td>
                                            <td align="center">find 必需。规定要查找的值。replace 必需。规定替换 find 中的值的值。string 必需。规定被搜索的字符串。count 可选。一个变量，对替换数进行计数。</td>

                                        </tr>
                                        <tr>
                                            <td>substr_replace(string,replacement,start,length)</td>
                                            <td align="center">把字符串的一部分替换为另一个字符串。适合用于替换自定位置的字符串。</td>
                                            <td align="center">string 必需。规定要检查的字符串。replacement 必需。规定要插入的字符串。start 必需。规定在字符串的何处开始替换。</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h3 id="使用正则"><a name="t21"></a>使用正则</h3>
                                    <p>如果使用正则替换，php中提供了preg_replace _callback和preg_replace 函数，preg_replace 原型如下：&nbsp;<br>mixed preg_replace ( mixed&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-6-Frame" class="MathJax"><span id="MathJax-Span-118" class="math"><span id="MathJax-Span-119" class="mrow"><span id="MathJax-Span-120" class="mi">p<span id="MathJax-Span-121" class="mi">a<span id="MathJax-Span-122" class="mi">t<span id="MathJax-Span-123" class="mi">t<span id="MathJax-Span-124" class="mi">e<span id="MathJax-Span-125" class="mi">r<span id="MathJax-Span-126" class="mi">n<span id="MathJax-Span-127" class="mo">,<span id="MathJax-Span-128" class="mi">m<span id="MathJax-Span-129" class="mi">i<span id="MathJax-Span-130" class="mi">x<span id="MathJax-Span-131" class="mi">e<span id="MathJax-Span-132" class="mi">d</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>replacement , mixed&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-7-Frame" class="MathJax"><span id="MathJax-Span-133" class="math"><span id="MathJax-Span-134" class="mrow"><span id="MathJax-Span-135" class="mi">s<span id="MathJax-Span-136" class="mi">u<span id="MathJax-Span-137" class="mi">b<span id="MathJax-Span-138" class="mi">j<span id="MathJax-Span-139" class="mi">e<span id="MathJax-Span-140" class="mi">c<span id="MathJax-Span-141" class="mi">t<span id="MathJax-Span-142" class="mo">[<span id="MathJax-Span-143" class="mo">,<span id="MathJax-Span-144" class="mi">i<span id="MathJax-Span-145" class="mi">n<span id="MathJax-Span-146" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span></span></span>limit = -1 [, int &amp;<span class="MathJax_Preview"><span id="MathJax-Element-8-Frame" class="MathJax"><span id="MathJax-Span-147" class="math"><span id="MathJax-Span-148" class="mrow"><span id="MathJax-Span-149" class="mi">c<span id="MathJax-Span-150" class="mi">o<span id="MathJax-Span-151" class="mi">u<span id="MathJax-Span-152" class="mi">n<span id="MathJax-Span-153" class="mi">t<span id="MathJax-Span-154" class="mo">]<span id="MathJax-Span-155" class="mo">]<span id="MathJax-Span-156" class="mo">)<span id="MathJax-Span-157" class="texatom"><span id="MathJax-Span-158" class="mrow"><span id="MathJax-Span-159" class="mo">函<span id="MathJax-Span-160" class="texatom"><span id="MathJax-Span-161" class="mrow"><span id="MathJax-Span-162" class="mo">数<span id="MathJax-Span-163" class="texatom"><span id="MathJax-Span-164" class="mrow"><span id="MathJax-Span-165" class="mo">功<span id="MathJax-Span-166" class="texatom"><span id="MathJax-Span-167" class="mrow"><span id="MathJax-Span-168" class="mo">能<span id="MathJax-Span-169" class="texatom"><span id="MathJax-Span-170" class="mrow"><span id="MathJax-Span-171" class="mo">描<span id="MathJax-Span-172" class="texatom"><span id="MathJax-Span-173" class="mrow"><span id="MathJax-Span-174" class="mo">述<span id="MathJax-Span-175" class="texatom"><span id="MathJax-Span-176" class="mrow"><span id="MathJax-Span-177" class="mo">：<span id="MathJax-Span-178" class="texatom"><span id="MathJax-Span-179" class="mrow"><span id="MathJax-Span-180" class="mo">在<span id="MathJax-Span-181" class="texatom"><span id="MathJax-Span-182" class="mrow"><span id="MathJax-Span-183" class="mo">字<span id="MathJax-Span-184" class="texatom"><span id="MathJax-Span-185" class="mrow"><span id="MathJax-Span-186" class="mo">符<span id="MathJax-Span-187" class="texatom"><span id="MathJax-Span-188" class="mrow"><span id="MathJax-Span-189" class="mo">串</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>subject中，查找<span class="MathJax_Preview"><span id="MathJax-Element-9-Frame" class="MathJax"><span id="MathJax-Span-190" class="math"><span id="MathJax-Span-191" class="mrow"><span id="MathJax-Span-192" class="mi">p<span id="MathJax-Span-193" class="mi">a<span id="MathJax-Span-194" class="mi">t<span id="MathJax-Span-195" class="mi">t<span id="MathJax-Span-196" class="mi">e<span id="MathJax-Span-197" class="mi">r<span id="MathJax-Span-198" class="mi">n<span id="MathJax-Span-199" class="mo">,<span id="MathJax-Span-200" class="texatom"><span id="MathJax-Span-201" class="mrow"><span id="MathJax-Span-202" class="mo">然<span id="MathJax-Span-203" class="texatom"><span id="MathJax-Span-204" class="mrow"><span id="MathJax-Span-205" class="mo">后<span id="MathJax-Span-206" class="texatom"><span id="MathJax-Span-207" class="mrow"><span id="MathJax-Span-208" class="mo">使<span id="MathJax-Span-209" class="texatom"><span id="MathJax-Span-210" class="mrow"><span id="MathJax-Span-211" class="mo">用</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>replacement 去替换，如果有<span class="MathJax_Preview"><span id="MathJax-Element-10-Frame" class="MathJax"><span id="MathJax-Span-212" class="math"><span id="MathJax-Span-213" class="mrow"><span id="MathJax-Span-214" class="mi">l<span id="MathJax-Span-215" class="mi">i<span id="MathJax-Span-216" class="mi">m<span id="MathJax-Span-217" class="mi">i<span id="MathJax-Span-218" class="mi">t<span id="MathJax-Span-219" class="texatom"><span id="MathJax-Span-220" class="mrow"><span id="MathJax-Span-221" class="mo">则<span id="MathJax-Span-222" class="texatom"><span id="MathJax-Span-223" class="mrow"><span id="MathJax-Span-224" class="mo">代<span id="MathJax-Span-225" class="texatom"><span id="MathJax-Span-226" class="mrow"><span id="MathJax-Span-227" class="mo">表<span id="MathJax-Span-228" class="texatom"><span id="MathJax-Span-229" class="mrow"><span id="MathJax-Span-230" class="mo">限<span id="MathJax-Span-231" class="texatom"><span id="MathJax-Span-232" class="mrow"><span id="MathJax-Span-233" class="mo">制<span id="MathJax-Span-234" class="texatom"><span id="MathJax-Span-235" class="mrow"><span id="MathJax-Span-236" class="mo">替<span id="MathJax-Span-237" class="texatom"><span id="MathJax-Span-238" class="mrow"><span id="MathJax-Span-239" class="mo">换<span id="MathJax-Span-240" class="mi">l<span id="MathJax-Span-241" class="mi">i<span id="MathJax-Span-242" class="mi">m<span id="MathJax-Span-243" class="mi">i<span id="MathJax-Span-244" class="mi">t<span id="MathJax-Span-245" class="texatom"><span id="MathJax-Span-246" class="mrow"><span id="MathJax-Span-247" class="mo">次<span id="MathJax-Span-248" class="texatom"><span id="MathJax-Span-249" class="mrow"><span id="MathJax-Span-250" class="mo">。<span id="MathJax-Span-251" class="mi">p<span id="MathJax-Span-252" class="mi">r<span id="MathJax-Span-253" class="mi">e<span id="MathJax-Span-254" class="msubsup"><span id="MathJax-Span-255" class="mi">g<span id="MathJax-Span-256" class="mi">r<span id="MathJax-Span-257" class="mi">e<span id="MathJax-Span-258" class="mi">p<span id="MathJax-Span-259" class="mi">l<span id="MathJax-Span-260" class="mi">a<span id="MathJax-Span-261" class="mi">c<span id="MathJax-Span-262" class="msubsup"><span id="MathJax-Span-263" class="mi">e<span id="MathJax-Span-264" class="mi">c<span id="MathJax-Span-265" class="mi">a<span id="MathJax-Span-266" class="mi">l<span id="MathJax-Span-267" class="mi">l<span id="MathJax-Span-268" class="mi">b<span id="MathJax-Span-269" class="mi">a<span id="MathJax-Span-270" class="mi">c<span id="MathJax-Span-271" class="mi">k<span id="MathJax-Span-272" class="texatom"><span id="MathJax-Span-273" class="mrow"><span id="MathJax-Span-274" class="mo">与<span id="MathJax-Span-275" class="mi">p<span id="MathJax-Span-276" class="mi">r<span id="MathJax-Span-277" class="mi">e<span id="MathJax-Span-278" class="msubsup"><span id="MathJax-Span-279" class="mi">g<span id="MathJax-Span-280" class="mi">r<span id="MathJax-Span-281" class="mi">e<span id="MathJax-Span-282" class="mi">p<span id="MathJax-Span-283" class="mi">l<span id="MathJax-Span-284" class="mi">a<span id="MathJax-Span-285" class="mi">c<span id="MathJax-Span-286" class="mi">e<span id="MathJax-Span-287" class="texatom"><span id="MathJax-Span-288" class="mrow"><span id="MathJax-Span-289" class="mo">功<span id="MathJax-Span-290" class="texatom"><span id="MathJax-Span-291" class="mrow"><span id="MathJax-Span-292" class="mo">能<span id="MathJax-Span-293" class="texatom"><span id="MathJax-Span-294" class="mrow"><span id="MathJax-Span-295" class="mo">相<span id="MathJax-Span-296" class="texatom"><span id="MathJax-Span-297" class="mrow"><span id="MathJax-Span-298" class="mo">识<span id="MathJax-Span-299" class="texatom"><span id="MathJax-Span-300" class="mrow"><span id="MathJax-Span-301" class="mo">，<span id="MathJax-Span-302" class="texatom"><span id="MathJax-Span-303" class="mrow"><span id="MathJax-Span-304" class="mo">不<span id="MathJax-Span-305" class="texatom"><span id="MathJax-Span-306" class="mrow"><span id="MathJax-Span-307" class="mo">同<span id="MathJax-Span-308" class="texatom"><span id="MathJax-Span-309" class="mrow"><span id="MathJax-Span-310" class="mo">的<span id="MathJax-Span-311" class="texatom"><span id="MathJax-Span-312" class="mrow"><span id="MathJax-Span-313" class="mo">是<span id="MathJax-Span-314" class="mi">p<span id="MathJax-Span-315" class="mi">r<span id="MathJax-Span-316" class="mi">e<span id="MathJax-Span-317" class="msubsup"><span id="MathJax-Span-318" class="mi">g<span id="MathJax-Span-319" class="mi">r<span id="MathJax-Span-320" class="mi">e<span id="MathJax-Span-321" class="mi">p<span id="MathJax-Span-322" class="mi">l<span id="MathJax-Span-323" class="mi">a<span id="MathJax-Span-324" class="mi">c<span id="MathJax-Span-325" class="msubsup"><span id="MathJax-Span-326" class="mi">e<span id="MathJax-Span-327" class="mi">b<span id="MathJax-Span-328" class="mi">a<span id="MathJax-Span-329" class="mi">c<span id="MathJax-Span-330" class="mi">k<span id="MathJax-Span-331" class="texatom"><span id="MathJax-Span-332" class="mrow"><span id="MathJax-Span-333" class="mo">使<span id="MathJax-Span-334" class="texatom"><span id="MathJax-Span-335" class="mrow"><span id="MathJax-Span-336" class="mo">用<span id="MathJax-Span-337" class="texatom"><span id="MathJax-Span-338" class="mrow"><span id="MathJax-Span-339" class="mo">一<span id="MathJax-Span-340" class="texatom"><span id="MathJax-Span-341" class="mrow"><span id="MathJax-Span-342" class="mo">个<span id="MathJax-Span-343" class="texatom"><span id="MathJax-Span-344" class="mrow"><span id="MathJax-Span-345" class="mo">回<span id="MathJax-Span-346" class="texatom"><span id="MathJax-Span-347" class="mrow"><span id="MathJax-Span-348" class="mo">调<span id="MathJax-Span-349" class="texatom"><span id="MathJax-Span-350" class="mrow"><span id="MathJax-Span-351" class="mo">函<span id="MathJax-Span-352" class="texatom"><span id="MathJax-Span-353" class="mrow"><span id="MathJax-Span-354" class="mo">数<span id="MathJax-Span-355" class="mi">c<span id="MathJax-Span-356" class="mi">a<span id="MathJax-Span-357" class="mi">l<span id="MathJax-Span-358" class="mi">l<span id="MathJax-Span-359" class="mi">b<span id="MathJax-Span-360" class="mi">a<span id="MathJax-Span-361" class="mi">c<span id="MathJax-Span-362" class="mi">k<span id="MathJax-Span-363" class="texatom"><span id="MathJax-Span-364" class="mrow"><span id="MathJax-Span-365" class="mo">来<span id="MathJax-Span-366" class="texatom"><span id="MathJax-Span-367" class="mrow"><span id="MathJax-Span-368" class="mo">代<span id="MathJax-Span-369" class="texatom"><span id="MathJax-Span-370" class="mrow"><span id="MathJax-Span-371" class="mo">替<span id="MathJax-Span-372" class="mi">r<span id="MathJax-Span-373" class="mi">e<span id="MathJax-Span-374" class="mi">p<span id="MathJax-Span-375" class="mi">l<span id="MathJax-Span-376" class="mi">a<span id="MathJax-Span-377" class="mi">c<span id="MathJax-Span-378" class="mi">e<span id="MathJax-Span-379" class="mi">m<span id="MathJax-Span-380" class="mi">e<span id="MathJax-Span-381" class="mi">n<span id="MathJax-Span-382" class="mi">t<span id="MathJax-Span-383" class="mo">.<span id="MathJax-Span-384" class="mo">−<span id="MathJax-Span-385" class="texatom"><span id="MathJax-Span-386" class="mrow"><span id="MathJax-Span-387" class="mo">例<span id="MathJax-Span-388" class="mn">1<span id="MathJax-Span-389" class="texatom"><span id="MathJax-Span-390" class="mrow"><span id="MathJax-Span-391" class="mo">将<span id="MathJax-Span-392" class="texatom"><span id="MathJax-Span-393" class="mrow"><span id="MathJax-Span-394" class="mo">字<span id="MathJax-Span-395" class="texatom"><span id="MathJax-Span-396" class="mrow"><span id="MathJax-Span-397" class="mo">符<span id="MathJax-Span-398" class="texatom"><span id="MathJax-Span-399" class="mrow"><span id="MathJax-Span-400" class="mo">串<span id="MathJax-Span-401" class="mo">”<span id="MathJax-Span-402" class="mi">h<span id="MathJax-Span-403" class="mi">e<span id="MathJax-Span-404" class="mi">l<span id="MathJax-Span-405" class="mi">l<span id="MathJax-Span-406" class="mi">o<span id="MathJax-Span-407" class="mo">,<span id="MathJax-Span-408" class="texatom"><span id="MathJax-Span-409" class="mrow"><span id="MathJax-Span-410" class="mo">中<span id="MathJax-Span-411" class="texatom"><span id="MathJax-Span-412" class="mrow"><span id="MathJax-Span-413" class="mo">国<span id="MathJax-Span-414" class="mo">”<span id="MathJax-Span-415" class="texatom"><span id="MathJax-Span-416" class="mrow"><span id="MathJax-Span-417" class="mo">中<span id="MathJax-Span-418" class="texatom"><span id="MathJax-Span-419" class="mrow"><span id="MathJax-Span-420" class="mo">的<span id="MathJax-Span-421" class="mi">h<span id="MathJax-Span-422" class="mi">e<span id="MathJax-Span-423" class="mi">l<span id="MathJax-Span-424" class="mi">l<span id="MathJax-Span-425" class="mi">o<span id="MathJax-Span-426" class="texatom"><span id="MathJax-Span-427" class="mrow"><span id="MathJax-Span-428" class="mo">替<span id="MathJax-Span-429" class="texatom"><span id="MathJax-Span-430" class="mrow"><span id="MathJax-Span-431" class="mo">换<span id="MathJax-Span-432" class="msup"><span id="MathJax-Span-433" class="texatom"><span id="MathJax-Span-434" class="mrow"><span id="MathJax-Span-435" class="mo">为<span id="MathJax-Span-436" class="mo">′<span id="MathJax-Span-437" class="texatom"><span id="MathJax-Span-438" class="mrow"><span id="MathJax-Span-439" class="mo">你<span id="MathJax-Span-440" class="msup"><span id="MathJax-Span-441" class="texatom"><span id="MathJax-Span-442" class="mrow"><span id="MathJax-Span-443" class="mo">好<span id="MathJax-Span-444" class="mo">′<span id="MathJax-Span-445" class="mo">;<span id="MathJax-Span-446" class="texatom"><span id="MathJax-Span-447" class="mrow"><span id="MathJax-Span-448" class="mo">如<span id="MathJax-Span-449" class="texatom"><span id="MathJax-Span-450" class="mrow"><span id="MathJax-Span-451" class="mo">果<span id="MathJax-Span-452" class="texatom"><span id="MathJax-Span-453" class="mrow"><span id="MathJax-Span-454" class="mo">不<span id="MathJax-Span-455" class="texatom"><span id="MathJax-Span-456" class="mrow"><span id="MathJax-Span-457" class="mo">是<span id="MathJax-Span-458" class="texatom"><span id="MathJax-Span-459" class="mrow"><span id="MathJax-Span-460" class="mo">用<span id="MathJax-Span-461" class="texatom"><span id="MathJax-Span-462" class="mrow"><span id="MathJax-Span-463" class="mo">正<span id="MathJax-Span-464" class="texatom"><span id="MathJax-Span-465" class="mrow"><span id="MathJax-Span-466" class="mo">则<span id="MathJax-Span-467" class="mo">:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str=’hello,中国’;&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-11-Frame" class="MathJax"><span id="MathJax-Span-468" class="math"><span id="MathJax-Span-469" class="mrow"><span id="MathJax-Span-470" class="mi">s<span id="MathJax-Span-471" class="mi">t<span id="MathJax-Span-472" class="mi">r<span id="MathJax-Span-473" class="mo">=<span id="MathJax-Span-474" class="mi">s<span id="MathJax-Span-475" class="mi">t<span id="MathJax-Span-476" class="msubsup"><span id="MathJax-Span-477" class="mi">r<span id="MathJax-Span-478" class="mi">r<span id="MathJax-Span-479" class="mi">e<span id="MathJax-Span-480" class="mi">p<span id="MathJax-Span-481" class="mi">l<span id="MathJax-Span-482" class="mi">a<span id="MathJax-Span-483" class="mi">c<span id="MathJax-Span-484" class="mi">e<span id="MathJax-Span-485" class="msup"><span id="MathJax-Span-486" class="mo">(<span id="MathJax-Span-487" class="mo">′<span id="MathJax-Span-488" class="mi">h<span id="MathJax-Span-489" class="mi">e<span id="MathJax-Span-490" class="mi">l<span id="MathJax-Span-491" class="mi">l<span id="MathJax-Span-492" class="msup"><span id="MathJax-Span-493" class="mi">o<span id="MathJax-Span-494" class="mo">′<span id="MathJax-Span-495" class="msup"><span id="MathJax-Span-496" class="mo">,<span id="MathJax-Span-497" class="mo">′<span id="MathJax-Span-498" class="texatom"><span id="MathJax-Span-499" class="mrow"><span id="MathJax-Span-500" class="mo">你<span id="MathJax-Span-501" class="msup"><span id="MathJax-Span-502" class="texatom"><span id="MathJax-Span-503" class="mrow"><span id="MathJax-Span-504" class="mo">好<span id="MathJax-Span-505" class="mo">′<span id="MathJax-Span-506" class="mo">,</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str)&nbsp;<br>或是使用<span class="MathJax_Preview"><span id="MathJax-Element-12-Frame" class="MathJax"><span id="MathJax-Span-507" class="math"><span id="MathJax-Span-508" class="mrow"><span id="MathJax-Span-509" class="mi">s<span id="MathJax-Span-510" class="mi">t<span id="MathJax-Span-511" class="mi">r<span id="MathJax-Span-512" class="mo">=<span id="MathJax-Span-513" class="mi">s<span id="MathJax-Span-514" class="mi">u<span id="MathJax-Span-515" class="mi">b<span id="MathJax-Span-516" class="mi">s<span id="MathJax-Span-517" class="mi">t<span id="MathJax-Span-518" class="msubsup"><span id="MathJax-Span-519" class="mi">r<span id="MathJax-Span-520" class="mi">r<span id="MathJax-Span-521" class="mi">e<span id="MathJax-Span-522" class="mi">p<span id="MathJax-Span-523" class="mi">l<span id="MathJax-Span-524" class="mi">a<span id="MathJax-Span-525" class="mi">c<span id="MathJax-Span-526" class="mi">e<span id="MathJax-Span-527" class="mo">(</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str,’你好’,0,5)&nbsp;<br>使用正则&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-13-Frame" class="MathJax"><span id="MathJax-Span-528" class="math"><span id="MathJax-Span-529" class="mrow"><span id="MathJax-Span-530" class="mi">p<span id="MathJax-Span-531" class="mi">a<span id="MathJax-Span-532" class="mi">t<span id="MathJax-Span-533" class="mi">t<span id="MathJax-Span-534" class="mi">e<span id="MathJax-Span-535" class="mi">r<span id="MathJax-Span-536" class="mi">n<span id="MathJax-Span-537" class="msup"><span id="MathJax-Span-538" class="mo">=<span id="MathJax-Span-539" class="mo">′<span id="MathJax-Span-540" class="texatom"><span id="MathJax-Span-541" class="mrow"><span id="MathJax-Span-542" class="mo">/<span id="MathJax-Span-543" class="mi">h<span id="MathJax-Span-544" class="mi">e<span id="MathJax-Span-545" class="mi">l<span id="MathJax-Span-546" class="mi">l<span id="MathJax-Span-547" class="mi">o<span id="MathJax-Span-548" class="msup"><span id="MathJax-Span-549" class="texatom"><span id="MathJax-Span-550" class="mrow"><span id="MathJax-Span-551" class="mo">/<span id="MathJax-Span-552" class="mo">′<span id="MathJax-Span-553" class="mo">;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str=preg_replace (<span class="MathJax_Preview"><span id="MathJax-Element-14-Frame" class="MathJax"><span id="MathJax-Span-554" class="math"><span id="MathJax-Span-555" class="mrow"><span id="MathJax-Span-556" class="mi">p<span id="MathJax-Span-557" class="mi">a<span id="MathJax-Span-558" class="mi">t<span id="MathJax-Span-559" class="mi">t<span id="MathJax-Span-560" class="mi">e<span id="MathJax-Span-561" class="mi">r<span id="MathJax-Span-562" class="mi">n<span id="MathJax-Span-563" class="msup"><span id="MathJax-Span-564" class="mo">,<span id="MathJax-Span-565" class="mo">′<span id="MathJax-Span-566" class="texatom"><span id="MathJax-Span-567" class="mrow"><span id="MathJax-Span-568" class="mo">你<span id="MathJax-Span-569" class="msup"><span id="MathJax-Span-570" class="texatom"><span id="MathJax-Span-571" class="mrow"><span id="MathJax-Span-572" class="mo">好<span id="MathJax-Span-573" class="mo">′<span id="MathJax-Span-574" class="mo">,</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str);&nbsp;<br>- 例2&nbsp;<br>去除字符串”gawwenngeeojjgegop”中连续相同的字母</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'gawwenngeeojjgegop';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/(.)\1/';
<span class="hljs-variable">$str=preg_replace(<span class="hljs-variable">$pattern,<span class="hljs-string">'',<span class="hljs-variable">$str);</span></span></span></span></span></span></span></span></code></pre>
                                    <p>解析：当然这样可能会遇到，当第一次去除了重复了字符串后，又出来重复的字符串。如字符串味’gewwenngeeojjgegop’,针对这中问题，当然，这样的话，通过判断，继续替换下去。</p>
                                    <ul>
                                        <li>例3&nbsp;<br>将字符串中”age13gegep3iorji65k65k”;中出现的连续两个数字改为第二个数字，如字符串中13被改为3</li>

                                    </ul>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'age13gegep3iorji65k65k';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/(\d)(\d)/';
<span class="hljs-variable">$str=preg_replace(<span class="hljs-variable">$pattern,<span class="hljs-string">'$2', <span class="hljs-variable">$str);</span></span></span></span></span></span></span></span></code></pre>
                                    <p>解析：$n在正则表达式外使用反向引用。n代表第几次匹配到的结果。</p>
                                    <h2 id="php中字符串分割"><a name="t22"></a>php中字符串分割</h2>
                                    <h3 id="不适用正则"><a name="t23"></a>不适用正则</h3>
                                    <p>php提供了explode函数去分割字符串，与其对应的是implode。关于explode原型如下：&nbsp;<br>array explode ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-15-Frame" class="MathJax"><span id="MathJax-Span-575" class="math"><span id="MathJax-Span-576" class="mrow"><span id="MathJax-Span-577" class="mi">d<span id="MathJax-Span-578" class="mi">e<span id="MathJax-Span-579" class="mi">l<span id="MathJax-Span-580" class="mi">i<span id="MathJax-Span-581" class="mi">m<span id="MathJax-Span-582" class="mi">i<span id="MathJax-Span-583" class="mi">t<span id="MathJax-Span-584" class="mi">e<span id="MathJax-Span-585" class="mi">r<span id="MathJax-Span-586" class="mo">,<span id="MathJax-Span-587" class="mi">s<span id="MathJax-Span-588" class="mi">t<span id="MathJax-Span-589" class="mi">r<span id="MathJax-Span-590" class="mi">i<span id="MathJax-Span-591" class="mi">n<span id="MathJax-Span-592" class="mi">g</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>string [, int $limit ] )&nbsp;<br>delimiter：边界上的分隔字符。&nbsp;<br>string：输入的字符串。&nbsp;<br>limit：如果设置了 limit 参数并且是正数，则返回的数组包含最多 limit 个元素，而最后那个元素将包含 string 的剩余部分。如果 limit 参数是负数，则返回除了最后的 -limit 个元素外的所有元素。如果 limit 是 0，则会被当做 1。</span></span></p>
                                    <h3 id="使用正则-1"><a name="t24"></a>使用正则</h3>
                                    <p>关于通过正则表达式进行字符串分割，php提供了split、preg_split 函数。preg_split() 函数，通常是比 split() 更快的替代方案。&nbsp;<br>array preg_split ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-16-Frame" class="MathJax"><span id="MathJax-Span-593" class="math"><span id="MathJax-Span-594" class="mrow"><span id="MathJax-Span-595" class="mi">p<span id="MathJax-Span-596" class="mi">a<span id="MathJax-Span-597" class="mi">t<span id="MathJax-Span-598" class="mi">t<span id="MathJax-Span-599" class="mi">e<span id="MathJax-Span-600" class="mi">r<span id="MathJax-Span-601" class="mi">n<span id="MathJax-Span-602" class="mo">,<span id="MathJax-Span-603" class="mi">s<span id="MathJax-Span-604" class="mi">t<span id="MathJax-Span-605" class="mi">r<span id="MathJax-Span-606" class="mi">i<span id="MathJax-Span-607" class="mi">n<span id="MathJax-Span-608" class="mi">g</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>subject [, int&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-17-Frame" class="MathJax"><span id="MathJax-Span-609" class="math"><span id="MathJax-Span-610" class="mrow"><span id="MathJax-Span-611" class="mi">l<span id="MathJax-Span-612" class="mi">i<span id="MathJax-Span-613" class="mi">m<span id="MathJax-Span-614" class="mi">i<span id="MathJax-Span-615" class="mi">t<span id="MathJax-Span-616" class="mo">=<span id="MathJax-Span-617" class="mo">−<span id="MathJax-Span-618" class="mn">1<span id="MathJax-Span-619" class="mo">[<span id="MathJax-Span-620" class="mo">,<span id="MathJax-Span-621" class="mi">i<span id="MathJax-Span-622" class="mi">n<span id="MathJax-Span-623" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>flags = 0 ]] )</span></span></span></span></p>
                                    <ul>
                                        <li>例题&nbsp;<br>将字符串 ‘<a href="http://blog.csdn.net/hsd2012/article/details/51152810">http://blog.csdn.net/hsd2012/article/details/51152810</a>‘按照’/’进行分割&nbsp;<br>解法一：</li>

                                    </ul>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012/article/details/51152810';
<span class="hljs-variable">$str=explode(<span class="hljs-string">'/', <span class="hljs-variable">$str);</span></span></span></span></span></code></pre>
                                    <p>解法二：</p>
                                    <pre name="code" class="prettyprint"><code class="hljs php has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012/article/details/51152810';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/\//';  <span class="hljs-comment">/*因为/为特殊字符，需要转移*/
<span class="hljs-variable">$str=preg_split (<span class="hljs-variable">$pattern, <span class="hljs-variable">$str);</span></span></span></span></span></span></span></span></code></pre>
                                    <h2 id="php中贪婪匹配与惰性匹配">php中贪婪匹配与惰性匹配</h2>
                                    <ul>
                                        <li>贪婪匹配：就是匹配尽可能多的字符。&nbsp;<br>比如，正则表达式中m.*n，它将匹配最长以m开始，n结尾的字符串。如果用它来搜索manmpndegenc的话，它将匹配到的字符串是manmpndegen而非man。可以这样想，当匹配到m的时候，它将从后面往前匹配字符n。</li>
                                        <li>懒惰匹配：就是匹配尽可能少的字符。&nbsp;<br>有的时候，我们需要并不是去贪婪匹配，而是尽可能少的去匹配。这时候，就需要将其转为惰性匹配。怎样将一个贪婪匹配转为惰性匹配呢？只需要在其后面添加一个”？”即可。如m.*?n将匹配manmpndegenc，匹配到的字符串是man。</li>

                                    </ul>
                                    <table>
                                        <thead>
                                        <tr><th>函数符</th><th align="center">描述</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>*?</td>
                                            <td align="center">零次或多次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>+?</td>
                                            <td align="center">一次或多次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>??</td>
                                            <td align="center">0次或1次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>{n,}?</td>
                                            <td align="center">至少n次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>{n,m}?</td>
                                            <td align="center">n到m次 ，但尽可能少的匹配</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h2 id="php正则表达式之回溯与固态分组"><a name="t26"></a>php正则表达式之回溯与固态分组</h2>
                                    <h3 id="回溯"><a name="t27"></a>回溯</h3>
                                    <p>首先我们需要清楚什么是回溯，回溯就像是在走岔路口，当遇到岔路的时候就先在每个路口做一个标记。如果走了死路，就可以照原路返回，直到遇见之前所做过的标记，标记着还未尝试过的道路。如果那条路也走不能，可以继续返回，找到下一个标记，如此重复，直到找到出路，或者直到完成所有没有尝试过的路。首先我们看例题</p>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'aageacwgewcaw';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/a\w*c/i';
<span class="hljs-variable">$str=preg_match(<span class="hljs-variable">$pattern, <span class="hljs-variable">$str);</span></span></span></span></span></span></span></code></pre>
                                    <p>看到上面的程序，可能都清楚是什么意思，就是匹配$str是否包含这样一个由”a+0个或多个字母+c”不区分大小写的字符串。但是至于程序怎样去匹配的呢？匹配的过程中，回溯了多少次呢？</p>
                                    <table>
                                        <thead>
                                        <tr><th>匹配过程</th><th align="center">接下来操作描述</th></tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>‘a\w*c’中a匹配到’aageacwgewcaw’中第一个字符a</td>
                                            <td align="center">\w进行下一个字符匹配</td>
                                        </tr>
                                        <tr>
                                            <td>因为\w是贪婪匹配，会一直匹配到’aageacwgewcaw’中最后一个字符w</td>
                                            <td align="center">c进行下一个字符匹配时</td>
                                        </tr>
                                        <tr>
                                            <td>‘a\w*c’中c发现没有可以匹配的</td>
                                            <td align="center">于是\w匹配进行第一次回溯，匹配到倒数第二个字符a</td>
                                        </tr>
                                        <tr>
                                            <td>‘a\w*c’中c发现还是没有可以匹配的</td>
                                            <td align="center">于是\w匹配进行第二次回溯，匹配到倒数第三个字符c</td>
                                        </tr>
                                        <tr>
                                            <td>‘a\w*c’中c匹配成功</td>
                                            <td align="center">匹配结束返回结果</td>
                                        </tr>
                                        </tbody>
                                    </table>
                                    <p>现在，如果我们将<span class="MathJax_Preview"><span id="MathJax-Element-18-Frame" class="MathJax"><span id="MathJax-Span-624" class="math"><span id="MathJax-Span-625" class="mrow"><span id="MathJax-Span-626" class="mi">p<span id="MathJax-Span-627" class="mi">a<span id="MathJax-Span-628" class="mi">t<span id="MathJax-Span-629" class="mi">t<span id="MathJax-Span-630" class="mi">e<span id="MathJax-Span-631" class="mi">r<span id="MathJax-Span-632" class="mi">n<span id="MathJax-Span-633" class="texatom"><span id="MathJax-Span-634" class="mrow"><span id="MathJax-Span-635" class="mo">改<span id="MathJax-Span-636" class="texatom"><span id="MathJax-Span-637" class="mrow"><span id="MathJax-Span-638" class="mo">为</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>pattern=’/a\w*?c/i’;又会回溯多少次呢？正确答案是回溯四次。</span></span></p>
                                    <h3 id="固态分组"><a name="t28"></a>固态分组</h3>
                                    <p>固态分组，目的就是减少回溯次数， 使用(?&gt;…)括号中的匹配时如果产生了备选状态，那么一旦离开括号便会被立即 引擎抛弃掉。举个典型的例子如： ‘\w+:’这个表达式在进行匹配时的流程是这样的，会优先去匹配所有的符合\w的字符，假如字符串的末尾没有’:’，即匹配没有找到冒号，此时触发回溯机制，他会迫使前面的\w+释放字符，并且在交还的字符中重新尝试与’:’作比对。但是问题出现在这里: \w是不包含冒号的，显然无论如何都不会匹配成功，可是依照回溯机制，引擎还是得硬着头皮往前找，这就是对资源的浪费。所以我们就需要避免这种回溯，对此的方法就是将前面匹配到的内容固化，不令其存储备用状态！，那么引擎就会因为没有备用状态可用而只得结束匹配过程。大大减少回溯的次数。&nbsp;<br>如下代码，就不会进行回溯：</p>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'nihaoaheloo';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/(?&gt;\w+):/';
<span class="hljs-variable">$rs=preg_match(<span class="hljs-variable">$pattern, <span class="hljs-variable">$str);</span></span></span></span></span></span></span></code></pre>
                                    <p>当然有的时候，又需慎用固态分组，如下,我要检查$str中是否包含以a结尾的字符串，很明显是包含的，但是因为使用了固态分组，反而达不到我们想要的效果</p>
                                    <pre name="code" class="prettyprint"><code class="hljs ruby has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'nihaoahelaa';
<span class="hljs-variable">$pattern1=<span class="hljs-string">'/(?&gt;\w+)a/';
<span class="hljs-variable">$pattern2=<span class="hljs-string">'/\w+a/';
<span class="hljs-variable">$rs=preg_match(<span class="hljs-variable">$pattern1, <span class="hljs-variable">$str);<span class="hljs-regexp">//<span class="hljs-number">0
<span class="hljs-variable">$rs=preg_match(<span class="hljs-variable">$pattern2, <span class="hljs-variable">$str);<span class="hljs-regexp">//<span class="hljs-number">1</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <p>php中其他常用字符串操作函数</p>
                                    <ul>
                                        <li>字符串截取截取&nbsp;<br>string substr ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-19-Frame" class="MathJax"><span id="MathJax-Span-639" class="math"><span id="MathJax-Span-640" class="mrow"><span id="MathJax-Span-641" class="mi">s<span id="MathJax-Span-642" class="mi">t<span id="MathJax-Span-643" class="mi">r<span id="MathJax-Span-644" class="mi">i<span id="MathJax-Span-645" class="mi">n<span id="MathJax-Span-646" class="mi">g<span id="MathJax-Span-647" class="mo">,<span id="MathJax-Span-648" class="mi">i<span id="MathJax-Span-649" class="mi">n<span id="MathJax-Span-650" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span>start [, int&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-20-Frame" class="MathJax"><span id="MathJax-Span-651" class="math"><span id="MathJax-Span-652" class="mrow"><span id="MathJax-Span-653" class="mi">l<span id="MathJax-Span-654" class="mi">e<span id="MathJax-Span-655" class="mi">n<span id="MathJax-Span-656" class="mi">g<span id="MathJax-Span-657" class="mi">t<span id="MathJax-Span-658" class="mi">h<span id="MathJax-Span-659" class="mo">]<span id="MathJax-Span-660" class="mo">)<span id="MathJax-Span-661" class="mi">s<span id="MathJax-Span-662" class="mi">t<span id="MathJax-Span-663" class="mi">r<span id="MathJax-Span-664" class="mi">i<span id="MathJax-Span-665" class="mi">n<span id="MathJax-Span-666" class="mi">g<span id="MathJax-Span-667" class="mi">m<span id="MathJax-Span-668" class="msubsup"><span id="MathJax-Span-669" class="mi">b<span id="MathJax-Span-670" class="mi">s<span id="MathJax-Span-671" class="mi">u<span id="MathJax-Span-672" class="mi">b<span id="MathJax-Span-673" class="mi">s<span id="MathJax-Span-674" class="mi">t<span id="MathJax-Span-675" class="mi">r<span id="MathJax-Span-676" class="mo">(<span id="MathJax-Span-677" class="mi">s<span id="MathJax-Span-678" class="mi">t<span id="MathJax-Span-679" class="mi">r<span id="MathJax-Span-680" class="mi">i<span id="MathJax-Span-681" class="mi">n<span id="MathJax-Span-682" class="mi">g</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str , int&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-21-Frame" class="MathJax"><span id="MathJax-Span-683" class="math"><span id="MathJax-Span-684" class="mrow"><span id="MathJax-Span-685" class="mi">s<span id="MathJax-Span-686" class="mi">t<span id="MathJax-Span-687" class="mi">a<span id="MathJax-Span-688" class="mi">r<span id="MathJax-Span-689" class="mi">t<span id="MathJax-Span-690" class="mo">[<span id="MathJax-Span-691" class="mo">,<span id="MathJax-Span-692" class="mi">i<span id="MathJax-Span-693" class="mi">n<span id="MathJax-Span-694" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span>length = NULL [, string $encoding = mb_internal_encoding() ]] )</span></span></span></span></span></span></li>
                                        <li>字符串中大小写转换&nbsp;<br>strtoupper&nbsp;<br>strtolower&nbsp;<br>ucfirst&nbsp;<br>ucwords</li>
                                        <li>字符串比较&nbsp;<br>-strcmp、strcasecmp、strnatcmp</li>
                                        <li>字符串过滤</li>
                                        <li>字符串翻转&nbsp;<br>strrev($str);</li>
                                        <li>字符串随机排序&nbsp;<br>string str_shuffle ( string $str )</li>

                                    </ul>
                                    <h1 id="补充"><a name="t30"></a>补充</h1>
                                    <h2 id="怎样进行邮箱匹配url匹配手机匹配"><a name="t31"></a>怎样进行邮箱匹配，url匹配，手机匹配</h2>
                                    <p>使用preg_match函数进行匹配，以下内容从TP中复制而来。&nbsp;<br>邮箱验证&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-22-Frame" class="MathJax"><span id="MathJax-Span-695" class="math"><span id="MathJax-Span-696" class="mrow"><span id="MathJax-Span-697" class="mi">p<span id="MathJax-Span-698" class="mi">a<span id="MathJax-Span-699" class="mi">t<span id="MathJax-Span-700" class="mi">t<span id="MathJax-Span-701" class="mi">e<span id="MathJax-Span-702" class="mi">r<span id="MathJax-Span-703" class="mi">n<span id="MathJax-Span-704" class="msup"><span id="MathJax-Span-705" class="mo">=<span id="MathJax-Span-706" class="mo">′<span id="MathJax-Span-707" class="msubsup"><span id="MathJax-Span-708" class="texatom"><span id="MathJax-Span-709" class="mrow"><span id="MathJax-Span-710" class="mo">/<span id="MathJax-Span-711" class="mtext">\w<span id="MathJax-Span-712" class="mo">+<span id="MathJax-Span-713" class="mo">(<span id="MathJax-Span-714" class="mo">[<span id="MathJax-Span-715" class="mo">−<span id="MathJax-Span-716" class="mo">+<span id="MathJax-Span-717" class="mo">.<span id="MathJax-Span-718" class="mo">]<span id="MathJax-Span-719" class="mtext">\w<span id="MathJax-Span-720" class="mo">+<span id="MathJax-Span-721" class="mo">)<span id="MathJax-Span-722" class="mo">∗<span id="MathJax-Span-723" class="texatom"><span id="MathJax-Span-724" class="mrow"><span id="MathJax-Span-725" class="mo">@<span id="MathJax-Span-726" class="mtext">\w<span id="MathJax-Span-727" class="mo">+<span id="MathJax-Span-728" class="mo">(<span id="MathJax-Span-729" class="mo">[<span id="MathJax-Span-730" class="mo">−<span id="MathJax-Span-731" class="mo">.<span id="MathJax-Span-732" class="mo">]<span id="MathJax-Span-733" class="mtext">\w<span id="MathJax-Span-734" class="mo">+<span id="MathJax-Span-735" class="mo">)<span id="MathJax-Span-736" class="mo">∗<span id="MathJax-Span-737" class="mtext">\.<span id="MathJax-Span-738" class="mtext">\w<span id="MathJax-Span-739" class="mo">+<span id="MathJax-Span-740" class="mo">(<span id="MathJax-Span-741" class="mo">[<span id="MathJax-Span-742" class="mo">−<span id="MathJax-Span-743" class="mo">.<span id="MathJax-Span-744" class="mo">]<span id="MathJax-Span-745" class="mtext">\w<span id="MathJax-Span-746" class="mo">+<span id="MathJax-Span-747" class="mo">)<span id="MathJax-Span-748" class="mo">∗</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>/’;&nbsp;<br>url匹配&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-23-Frame" class="MathJax"><span id="MathJax-Span-749" class="math"><span id="MathJax-Span-750" class="noError">pattern='/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&amp;~`@[\]\':+!\.#\w]*)?/’;&nbsp;<br>手机验证&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-24-Frame" class="MathJax"><span id="MathJax-Span-751" class="math"><span id="MathJax-Span-752" class="mrow"><span id="MathJax-Span-753" class="mi">p<span id="MathJax-Span-754" class="mi">a<span id="MathJax-Span-755" class="mi">t<span id="MathJax-Span-756" class="mi">t<span id="MathJax-Span-757" class="mi">e<span id="MathJax-Span-758" class="mi">r<span id="MathJax-Span-759" class="mi">n<span id="MathJax-Span-760" class="msup"><span id="MathJax-Span-761" class="mo">=<span id="MathJax-Span-762" class="mo">′<span id="MathJax-Span-763" class="msubsup"><span id="MathJax-Span-764" class="texatom"><span id="MathJax-Span-765" class="mrow"><span id="MathJax-Span-766" class="mo">/<span id="MathJax-Span-767" class="mn">1<span id="MathJax-Span-768" class="mo">[<span id="MathJax-Span-769" class="mn">3458<span id="MathJax-Span-770" class="mo">]<span id="MathJax-Span-771" class="mtext">\d<span id="MathJax-Span-772" class="texatom"><span id="MathJax-Span-773" class="mrow"><span id="MathJax-Span-774" class="mn">10</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>/’;</span></span></span></span></span></span></span></span></p>
                                    <h2 id="php中正则的优缺点"><a name="t32"></a>php中正则的优缺点</h2>
                                    <p>php中正则在某些时候，能帮我们解决php函数很多困难的匹配或是替换。然后php中正则的效率，往往是我们需要考虑的，所以在某些时候，能不用正则还是尽量不去用它，除非，某些场合必须用到，或是我们能够有效减少其回溯次数。</p></div><div id="MySignature"></div>
                                <div class="clear"></div>
                                <div id="blog_post_info_block">
                                    <div id="BlogPostCategory"></div>
                                    <div id="EntryTag"></div>
                                    <div id="blog_post_info"><div id="green_channel">
                                        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(5718319,cb_blogId,1);green_channel_success(this,'谢谢推荐！');">好文要顶</a>
                                        <a id="green_channel_follow" onclick="follow('985de844-ca18-e611-9fc1-ac853d9f53cc');" href="javascript:void(0);">关注我</a>
                                        <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
                                        <a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="//common.cnblogs.com/images/icon_weibo_24.png" alt=""></a>
                                        <a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="//common.cnblogs.com/images/wechat.png" alt=""></a>
                                    </div>
                                        <div id="author_profile">
                                            <div id="author_profile_info" class="author_profile_info">
                                                <a href="http://home.cnblogs.com/u/hellohell/" target="_blank"><img src="//pic.cnblogs.com/face/955709/20160801134006.png" class="author_avatar" alt=""></a>
                                                <div id="author_profile_detail" class="author_profile_info">
                                                    <a href="http://home.cnblogs.com/u/hellohell/">helloworldlee</a><br>
                                                    <a href="http://home.cnblogs.com/u/hellohell/followees">关注 - 2</a><br>
                                                    <a href="http://home.cnblogs.com/u/hellohell/followers">粉丝 - 5</a>
                                                </div>
                                            </div>
                                            <div class="clear"></div>
                                            <div id="author_profile_honor"></div>
                                            <div id="author_profile_follow">
                                                <a href="javascript:void(0);" onclick="follow('985de844-ca18-e611-9fc1-ac853d9f53cc');return false;">+加关注</a>
                                            </div>
                                        </div>
                                        <div id="div_digg">
                                            <div class="diggit" onclick="votePost(5718319,'Digg')">
                                                <span class="diggnum" id="digg_count">2</span>
                                            </div>
                                            <div class="buryit" onclick="votePost(5718319,'Bury')">
                                                <span class="burynum" id="bury_count">1</span>
                                            </div>
                                            <div class="clear"></div>
                                            <div class="diggword" id="digg_tips">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clear"></div>
                                    <div id="post_next_prev"><a href="http://www.cnblogs.com/hellohell/p/5718252.html" class="p_n_p_prefix">« </a> 上一篇：<a href="http://www.cnblogs.com/hellohell/p/5718252.html" title="发布于2016-07-29 14:25">MySQL的Query Cache原理分析</a><br><a href="http://www.cnblogs.com/hellohell/p/5718345.html" class="p_n_p_prefix">» </a> 下一篇：<a href="http://www.cnblogs.com/hellohell/p/5718345.html" title="发布于2016-07-29 14:44">二叉树相关面试题</a><br></div>
                                </div>


                            </div>
                            <div class="postDesc">posted @ <span id="post-date">2016-07-29 14:38</span> <a href="http://www.cnblogs.com/hellohell/">helloworldlee</a> 阅读(<span id="post_view_count">32015</span>) 评论(<span id="post_comment_count">1</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=5718319" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(5718319);return false;">收藏</a></div>
                        </div>
                        <script type="text/javascript">var allowComments=true,cb_blogId=285161,cb_entryId=5718319,cb_blogApp=currentBlogApp,cb_blogUserGuid='985de844-ca18-e611-9fc1-ac853d9f53cc',cb_entryCreatedDate='2016/7/29 14:38:00';loadViewCount(cb_entryId);</script>

                    </div><!--end: topics 文章、评论容器-->
                </div><a name="!comments"></a><div id="blog-comments-placeholder"><div id="comments_pager_top"></div>
                <br>
                <div class="feedback_area_title">评论列表</div>
                <div class="feedbackNoItems"></div>

                <div class="feedbackItem">
                    <div class="feedbackListSubtitle">
                        <div class="feedbackManage">
                            &nbsp;&nbsp;<span class="comment_actions"></span>
                        </div>
                        <a href="#3712788" class="layer">#1楼</a><a name="3712788" id="comment_anchor_3712788"></a><span id="comment-maxId" style="display:none;">3712788</span><span id="comment-maxDate" style="display:none;">2017/6/12 19:16:31</span>  <span class="comment_date">2017-06-12 19:16</span> <a id="a_comment_author_3712788" href="http://www.cnblogs.com/hll1688/" target="_blank">阿木木ll</a> <a href="http://msg.cnblogs.com/send/%E9%98%BF%E6%9C%A8%E6%9C%A8ll" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
                    </div>
                    <div class="feedbackCon">
                        <div id="comment_body_3712788" class="blog_comment_body">手机验证怕是有问题啊，<br> "/^1[34578]\d{9}$/";</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3712788,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3712788,'Bury',this)">反对(0)</a></div><span id="comment_3712788_avatar" style="display:none;">http://pic.cnblogs.com/face/880283/20161015222705.png</span>
                    </div>
                </div>
                <div id="comments_pager_bottom"></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
                <div id="comment_form" class="commentform">
                    <a name="commentform"></a>
                    <div id="divCommentShow"></div>
                    <div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="#" onclick="return RefreshPage();">刷新页面</a><a href="#top">返回顶部</a></div>
                    <div id="comment_form_container"><div class="login_tips">注册用户登录后才能发表评论，请 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return login('commentform');">登录</a> 或 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return register();">注册</a>，<a href="http://www.cnblogs.com">访问</a>网站首页。</div></div>
                    <div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
                    <div id="ad_t2"></div>
                    <div id="opt_under_post"></div>
                    <div id="cnblogs_c1" class="c_ad_block"></div>
                    <div id="under_post_news"><div class="itnews c_ad_block"><b>最新IT新闻</b>:<br> ·  <a href="http://news.cnblogs.com/n/572569/" target="_blank">王思聪被讨薪续：熊猫官方表示从未违约 前员工称主播狼心狗肺</a><br> ·  <a href="http://news.cnblogs.com/n/572568/" target="_blank">亚马逊升级Echo软件 现在智能音箱能当对讲机使用啦</a><br> ·  <a href="http://news.cnblogs.com/n/572567/" target="_blank">FB、微软、YouTube和Twitter四巨头联手反恐</a><br> ·  <a href="http://news.cnblogs.com/n/572566/" target="_blank">身处激烈竞争的芯片市场，英伟达如何让股价一年翻了4倍？</a><br> ·  <a href="http://news.cnblogs.com/n/572565/" target="_blank">Google精英黑客团队Project Zero：守护全世界的安全</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="_blank">更多新闻...</a></div></div>
                    <div id="cnblogs_c2" class="c_ad_block"></div>
                    <div id="under_post_kb"><div class="itnews c_ad_block" id="kb_block"><b>最新知识库文章</b>:<br><div id="kb_recent"> ·  <a href="http://kb.cnblogs.com/page/570194/" target="_blank">小printf的故事：什么是真正的程序员？</a><br> ·  <a href="http://kb.cnblogs.com/page/569992/" target="_blank">程序员的工作、学习与绩效</a><br> ·  <a href="http://kb.cnblogs.com/page/569056/" target="_blank">软件开发为什么很难</a><br> ·  <a href="http://kb.cnblogs.com/page/565901/" target="_blank">唱吧DevOps的落地，微服务CI/CD的范本技术解读</a><br> ·  <a href="http://kb.cnblogs.com/page/566523/" target="_blank">程序员，如何从平庸走向理想？</a><br></div>» <a href="http://kb.cnblogs.com/" target="_blank">更多知识库文章...</a></div></div>
                    <div id="HistoryToday" class="c_ad_block"></div>
                    <script type="text/javascript">
                        fixPostBody();
                        setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
                        deliverAdT2();
                        deliverAdC1();
                        deliverAdC2();
                        loadNewsAndKb();
                        loadBlogSignature();
                        LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
                        GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate);
                        loadOptUnderPost();
                        GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);
                    </script>
                </div>


            </div><!--end: forFlow -->
        </div><!--end: mainContent 主体内容容器-->

        <div id="sideBar">
            <div id="sideBarMain">

                <!--done-->
                <div class="newsItem">
                    <h3 class="catListTitle">公告</h3>
                    <div id="blog-news"><div id="profile_block">昵称：<a href="http://home.cnblogs.com/u/hellohell/">helloworldlee</a><br>园龄：<a href="http://home.cnblogs.com/u/hellohell/" title="入园时间：2016-05-13">1年1个月</a><br>粉丝：<a href="http://home.cnblogs.com/u/hellohell/followers/">5</a><br>关注：<a href="http://home.cnblogs.com/u/hellohell/followees/">2</a><div id="p_b_follow"><a href="javascript:void(0);" onclick="follow('985de844-ca18-e611-9fc1-ac853d9f53cc')">+加关注</a></div></div></div><script type="text/javascript">loadBlogNews();</script>
                </div>

                <div id="blog-calendar"><table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="日历">
                    <tbody><tr><td colspan="7"><table class="CalTitle" cellspacing="0">
                        <tbody><tr><td class="CalNextPrev"><a href="javascript:void(0);" onclick="loadBlogCalendar('2017/05/01');return false;">&lt;</a></td><td align="center">2017年6月</td><td class="CalNextPrev" align="right"><a href="javascript:void(0);" onclick="loadBlogCalendar('2017/07/01');return false;">&gt;</a></td></tr>
                        </tbody></table></td></tr><tr><th class="CalDayHeader" align="center" abbr="日" scope="col">日</th><th class="CalDayHeader" align="center" abbr="一" scope="col">一</th><th class="CalDayHeader" align="center" abbr="二" scope="col">二</th><th class="CalDayHeader" align="center" abbr="三" scope="col">三</th><th class="CalDayHeader" align="center" abbr="四" scope="col">四</th><th class="CalDayHeader" align="center" abbr="五" scope="col">五</th><th class="CalDayHeader" align="center" abbr="六" scope="col">六</th></tr><tr><td class="CalOtherMonthDay" align="center">28</td><td class="CalOtherMonthDay" align="center">29</td><td class="CalOtherMonthDay" align="center">30</td><td class="CalOtherMonthDay" align="center">31</td><td align="center">1</td><td align="center">2</td><td class="CalWeekendDay" align="center">3</td></tr><tr><td class="CalWeekendDay" align="center">4</td><td align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">9</td><td class="CalWeekendDay" align="center">10</td></tr><tr><td class="CalWeekendDay" align="center">11</td><td align="center">12</td><td align="center">13</td><td align="center">14</td><td align="center">15</td><td align="center">16</td><td class="CalWeekendDay" align="center">17</td></tr><tr><td class="CalWeekendDay" align="center">18</td><td align="center">19</td><td align="center">20</td><td align="center">21</td><td align="center"><a href="http://www.cnblogs.com/hellohell/archive/2017/06/22.html"><u>22</u></a></td><td align="center">23</td><td class="CalWeekendDay" align="center">24</td></tr><tr><td class="CalWeekendDay" align="center">25</td><td align="center">26</td><td class="CalTodayDay" align="center">27</td><td align="center">28</td><td align="center">29</td><td align="center">30</td><td class="CalOtherMonthDay" align="center">1</td></tr><tr><td class="CalOtherMonthDay" align="center">2</td><td class="CalOtherMonthDay" align="center">3</td><td class="CalOtherMonthDay" align="center">4</td><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td><td class="CalOtherMonthDay" align="center">7</td><td class="CalOtherMonthDay" align="center">8</td></tr>
                    </tbody></table></div><script type="text/javascript">loadBlogDefaultCalendar();</script>

                <div id="leftcontentcontainer">
                    <div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
                        <div id="sidebar_search" class="mySearch">
                            <h3 class="catListTitle">搜索</h3>
                            <div id="sidebar_search_box">
                                <div id="widget_my_zzk" class="div_my_zzk"><input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="找找看" id="btnZzk" class="btn_my_zzk"></div>
                                <div id="widget_my_google" class="div_my_zzk"><input type="text" name="google_q" id="google_q" onkeydown="return google_go_enter(event)" class="input_my_zzk">&nbsp;<input onclick="google_go()" type="button" value="谷歌搜索" class="btn_my_zzk"></div>
                            </div>
                        </div>

                    </div><div id="sidebar_shortcut" class="sidebar-block">
                        <div class="catListLink">
                            <h3 class="catListTitle">常用链接</h3>
                            <ul>
                                <li><a href="http://www.cnblogs.com/hellohell/p/" title="我的博客的随笔列表">我的随笔</a></li><li><a href="http://www.cnblogs.com/hellohell/MyComments.html" title="我发表过的评论列表">我的评论</a></li><li><a href="http://www.cnblogs.com/hellohell/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li><li><a href="http://www.cnblogs.com/hellohell/RecentComments.html" title="我的博客的评论列表">最新评论</a></li><li><a href="http://www.cnblogs.com/hellohell/tag/" title="我的博客的标签列表">我的标签</a></li>
                            </ul>
                            <div id="itemListLin_con" style="display:none;">
                                <ul>

                                </ul>
                            </div>
                        </div></div><div id="sidebar_toptags" class="sidebar-block"></div><div id="sidebar_categories">
                        <div id="sidebar_postarchive" class="catListPostArchive sidebar-block">
                            <h3 class="catListTitle">随笔档案</h3>

                            <ul>

                                <li><a id="CatList_LinkList_0_Link_0" href="http://www.cnblogs.com/hellohell/archive/2017/06.html">2017年6月 (1)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_1" href="http://www.cnblogs.com/hellohell/archive/2017/03.html">2017年3月 (2)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_2" href="http://www.cnblogs.com/hellohell/archive/2017/02.html">2017年2月 (3)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_3" href="http://www.cnblogs.com/hellohell/archive/2017/01.html">2017年1月 (1)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_4" href="http://www.cnblogs.com/hellohell/archive/2016/12.html">2016年12月 (5)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_5" href="http://www.cnblogs.com/hellohell/archive/2016/11.html">2016年11月 (2)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_6" href="http://www.cnblogs.com/hellohell/archive/2016/10.html">2016年10月 (2)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_7" href="http://www.cnblogs.com/hellohell/archive/2016/09.html">2016年9月 (1)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_8" href="http://www.cnblogs.com/hellohell/archive/2016/08.html">2016年8月 (9)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_9" href="http://www.cnblogs.com/hellohell/archive/2016/07.html">2016年7月 (8)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_10" href="http://www.cnblogs.com/hellohell/archive/2016/06.html">2016年6月 (5)</a> </li>

                            </ul>

                        </div>

                    </div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap">
                        <div class="catListComment">
                            <h3 class="catListTitle">最新评论</h3>

                            <div id="RecentCommentsBlock"><ul>
                                <li class="recent_comment_title"><a href="http://www.cnblogs.com/hellohell/p/5718319.html#3712788">1. Re:php中正则表达式详解</a></li>
                                <li class="recent_comment_body">手机验证怕是有问题啊，<br> "/^1[34578]\d{9}$/";</li>
                                <li class="recent_comment_author">--阿木木ll</li>
                            </ul>
                            </div>
                        </div>
                    </div></div><div id="sidebar_topviewedposts" class="sidebar-block"><div id="topview_posts_wrap">
                        <div class="catListView">
                            <h3 class="catListTitle">阅读排行榜</h3>
                            <div id="TopViewPostsBlock"><ul><li><a href="http://www.cnblogs.com/hellohell/p/5718319.html">1. php中正则表达式详解(32012)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5718175.html">2. PHP实现各种经典算法(7060)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5718205.html">3. php通过Mysqli和PDO连接mysql数据详解(4593)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5718238.html">4. MySQL查询优化器工作原理解析(1598)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5733712.html">5. PHPDocument 代码注释规范总结(444)</a></li></ul></div>
                        </div>
                    </div></div><div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap">
                        <div class="catListFeedback">
                            <h3 class="catListTitle">评论排行榜</h3>
                            <div id="TopFeedbackPostsBlock"><ul><li><a href="http://www.cnblogs.com/hellohell/p/5718319.html">1. php中正则表达式详解(1)</a></li></ul></div>
                        </div>
                    </div></div><div id="sidebar_topdiggedposts" class="sidebar-block"><div id="topdigg_posts_wrap">
                        <div class="catListView">
                            <h3 class="catListTitle">推荐排行榜</h3>
                            <div id="TopDiggPostsBlock"><ul><li><a href="http://www.cnblogs.com/hellohell/p/5718319.html">1. php中正则表达式详解(2)</a></li></ul></div>
                        </div></div></div></div><script type="text/javascript">loadBlogSideColumn();</script>
                </div>

            </div><!--end: sideBarMain -->
        </div><!--end: sideBar 侧边栏容器 -->
        <div class="clear"></div>
    </div><!--end: main -->
    <div class="clear"></div>
    <div id="footer">

        <!--done-->
        Copyright ©2017 helloworldlee
    </div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->


<audio controls="controls" style="display: none;"></audio></body><style type="text/css">#yddContainer{display:block;font-family:Microsoft YaHei;position:relative;width:100%;height:100%;top:-4px;left:-4px;font-size:12px;border:1px solid}#yddTop{display:block;height:22px}#yddTopBorderlr{display:block;position:static;height:17px;padding:2px 28px;line-height:17px;font-size:12px;color:#5079bb;font-weight:bold;border-style:none solid;border-width:1px}#yddTopBorderlr .ydd-sp{position:absolute;top:2px;height:0;overflow:hidden}.ydd-icon{left:5px;width:17px;padding:0px 0px 0px 0px;padding-top:17px;background-position:-16px -44px}.ydd-close{right:5px;width:16px;padding-top:16px;background-position:left -44px}#yddKeyTitle{float:left;text-decoration:none}#yddMiddle{display:block;margin-bottom:10px}.ydd-tabs{display:block;margin:5px 0;padding:0 5px;height:18px;border-bottom:1px solid}.ydd-tab{display:block;float:left;height:18px;margin:0 5px -1px 0;padding:0 4px;line-height:18px;border:1px solid;border-bottom:none}.ydd-trans-container{display:block;line-height:160%}.ydd-trans-container a{text-decoration:none;}#yddBottom{position:absolute;bottom:0;left:0;width:100%;height:22px;line-height:22px;overflow:hidden;background-position:left -22px}.ydd-padding010{padding:0 10px}#yddWrapper{color:#252525;z-index:10001;background:url(chrome-extension://eopjamdnofihpioajgfdikhhbobonhbb/ab20.png);}#yddContainer{background:#fff;border-color:#4b7598}#yddTopBorderlr{border-color:#f0f8fc}#yddWrapper .ydd-sp{background-image:url(chrome-extension://eopjamdnofihpioajgfdikhhbobonhbb/ydd-sprite.png)}#yddWrapper a,#yddWrapper a:hover,#yddWrapper a:visited{color:#50799b}#yddWrapper .ydd-tabs{color:#959595}.ydd-tabs,.ydd-tab{background:#fff;border-color:#d5e7f3}#yddBottom{color:#363636}#yddWrapper{min-width:250px;max-width:400px;}</style></html><html lang="zh-cn"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>php中正则表达式详解 - helloworldlee - 博客园</title>
    <link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=m_FXmwz3wxZoecUwNEK23PAzc-j9vbX_C6MblJ5ouMc1">
    <link id="MainCss" type="text/css" rel="stylesheet" href="/skins/BlackLowKey/bundle-BlackLowKey.css?v=B7-m2NxlKbJ6xN_kGRXgbaLp9_4SHPK1jC_DQ8UbhqA1">
    <link id="mobile-style" media="only screen and (max-width: 768px)" type="text/css" rel="stylesheet" href="/skins/BlackLowKey/bundle-BlackLowKey-mobile.css?v=hM_4ic4i3O5wKXUjikUYwUGh6o9_4est1wSubdkIKhE1">
    <link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/hellohell/rss">
    <link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/hellohell/rsd.xml">
    <link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/hellohell/wlwmanifest.xml">
    <script async="" src="https://www.google-analytics.com/analytics.js"></script><script src="//common.cnblogs.com/script/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">var currentBlogApp = 'hellohell', cb_enable_mathjax=false;var isLogined=false;</script>
    <script src="/bundles/blog-common.js?v=E1-LyrzANB2jbN9omtnpOHx3eU0Kt3DyislfhU0b5p81" type="text/javascript"></script>
</head>
<body>
<a name="top"></a>

<!--done-->
<div id="home">
    <div id="header">
        <div id="blogTitle">
            <a id="lnkBlogLogo" href="http://www.cnblogs.com/hellohell/"><img id="blogLogo" src="/Skins/custom/images/logo.gif" alt="返回主页"></a>

            <!--done-->
            <h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/hellohell/">hello world</a></h1>
            <h2>阅读的意义就在于引发我们的思考，不动脑筋的阅读，只能称之为消遣。</h2>




        </div><!--end: blogTitle 博客的标题和副标题 -->
        <div id="navigator">

            <ul id="navList">
                <li><a id="blog_nav_sitehome" class="menu" href="http://www.cnblogs.com/">博客园</a></li>
                <li><a id="blog_nav_myhome" class="menu" href="http://www.cnblogs.com/hellohell/">首页</a></li>
                <li><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li>
                <li><a id="blog_nav_contact" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/helloworldlee">联系</a></li>
                <li><a id="blog_nav_rss" class="menu" href="http://www.cnblogs.com/hellohell/rss">订阅</a>
                    <!--<a id="blog_nav_rss_image" class="aHeaderXML" href="http://www.cnblogs.com/hellohell/rss"><img src="//www.cnblogs.com/images/xml.gif" alt="订阅" /></a>--></li>
                <li><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">管理</a></li>
            </ul>
            <div class="blogStats">

                <div id="blog_stats">
                    <span id="stats_post_count">随笔 - 39&nbsp; </span>
                    <span id="stats_article_count">文章 - 0&nbsp; </span>
                    <span id="stats-comment_count">评论 - 1</span>
                </div>

            </div><!--end: blogStats -->
        </div><!--end: navigator 博客导航栏 -->
    </div><!--end: header 头部 -->

    <div id="main">
        <div id="mainContent">
            <div class="forFlow">

                <div id="post_detail">
                    <!--done-->
                    <div id="topics">
                        <div class="post">
                            <h1 class="postTitle">
                                <a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/hellohell/p/5718319.html">php中正则表达式详解</a>
                            </h1>
                            <div class="clear"></div>
                            <div class="postBody">
                                <div id="cnblogs_post_body"><h1 id="概述">概述</h1>
                                    <p>正则表达式是一种描述字符串结果的语法规则，是一个特定的格式化模式，可以匹配、替换、截取匹配的字符串。常用的语言基本上都有正则表达式，如JavaScript、java等。其实，只有了解一种语言的正则使用，其他语言的正则使用起来，就相对简单些。文本主要围绕解决下面问题展开。</p>
                                    <ul>
                                        <li>有哪些常用的转义字符</li>
                                        <li>什么是限定符与定位符</li>
                                        <li>什么是单词定位符</li>
                                        <li>特殊字符有哪些</li>
                                        <li>什么是逆向引用以及怎样使用逆向引用</li>
                                        <li>匹配模式</li>
                                        <li>php中怎样使用正则表达式</li>
                                        <li>php中哪些方面需要用到正则</li>
                                        <li>怎样进行邮箱匹配，url匹配，手机匹配</li>
                                        <li>怎样使用正则替换字符串中某些字符</li>
                                        <li>贪婪匹配与惰性匹配区别</li>
                                        <li>正则表达式之回溯与固态分组</li>
                                        <li>正则优缺点有哪些</li>
                                    </ul>
                                    <h1 id="正则表达式的基本知识汇总"><a name="t1"></a>正则表达式的基本知识汇总</h1>
                                    <h1 id="行定位符与"><a name="t2"></a>行定位符（^与$）</h1>
                                    <p>行定位符是用来描述字符串的边界。<code>“$”</code>表示行结尾<code>“^”</code>表示行开始如<code>"^de"</code>，表示以de开头的字符串&nbsp;<code>"de$"</code>,表示以de结尾的字符串。</p>
                                    <h2 id="单词定界符"><a name="t3"></a>单词定界符</h2>
                                    <p>我们在查找的一个单词的时候，如an是否在一个字符串”gril and body”中存在，很明显如果匹配的话，an肯定是可以匹配字符串“gril and body”匹配到，怎样才能让其匹配单词，而不是单词的一部分呢？这时候，我们可以是哟个单词定界符\b。&nbsp;<br>\ban\b 去匹配”gril and body”的话，就会提示匹配不到。&nbsp;<br>当然还有一个大写的\B，它的意思，和\b正好相反，它匹配的字符串不能使一个完整的单词，而是其他单词或字符串中的一部分。如\Ban\B。</p>
                                    <h2 id="选择字符-表示或"><a name="t4"></a>选择字符(|) ，表示或</h2>
                                    <p>选择字符表示或的意思。如Aa|aA，表示Aa或者是aA的意思。注意使用”[]”与”|”的区别，在于”[]”只能匹配单个字符，而”|”可以匹配任意长度的字符串。在使用”[]”的时候，往往配合连接字符”-“一起使用，如[a-d],代表a或b或c或d。</p>
                                    <h2 id="排除字符排除操作"><a name="t5"></a>排除字符，排除操作</h2>
                                    <p>正则表达式提供了”^”来表示排除不符合的字符，^一般放在[]中。如[^1-5]，该字符不是1~5之间的数字。</p>
                                    <h2 id="限定符nm"><a name="t6"></a>限定符(？*+{n，m})</h2>
                                    <p>限定符主要是用来限定每个字符串出现的次数。</p>
                                    <table>
                                        <thead>
                                        <tr><th>限定字符</th><th align="center">含义</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>？</td>
                                            <td align="center">零次或一次</td>

                                        </tr>
                                        <tr>
                                            <td>*</td>
                                            <td align="center">零次或多次</td>

                                        </tr>
                                        <tr>
                                            <td>+</td>
                                            <td align="center">一次或多次</td>

                                        </tr>
                                        <tr>
                                            <td>{n}</td>
                                            <td align="center">n次</td>

                                        </tr>
                                        <tr>
                                            <td>{n,}</td>
                                            <td align="center">至少n次</td>

                                        </tr>
                                        <tr>
                                            <td>{n,m}</td>
                                            <td align="center">n到m次</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <p>如(D+)表示一个或多个D</p>
                                    <h2 id="点号操作符"><a name="t7"></a>点号操作符</h2>
                                    <p>匹配任意一个字符（不包含换行符）</p>
                                    <h2 id="表达式中的反斜杠"><a name="t8"></a>表达式中的反斜杠(<code>\</code>)</h2>
                                    <p>表达式中的反斜杠有多重意义，如转义、指定预定义的字符集、定义断言、显示不打印的字符。</p>
                                    <h3 id="转义字符"><a name="t9"></a>转义字符</h3>
                                    <p>转义字符主要是将一些特殊字符转为普通字符。而这些常用特殊字符有”.”，”?”、”\”等。</p>
                                    <h3 id="指定预定义的字符集"><a name="t10"></a>指定预定义的字符集</h3>
                                    <table>
                                        <thead>
                                        <tr><th>字符</th><th align="center">含义</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>\d</td>
                                            <td align="center">任意一个十进制数字[0-9]</td>

                                        </tr>
                                        <tr>
                                            <td>\D</td>
                                            <td align="center">任意一个非十进制数字</td>

                                        </tr>
                                        <tr>
                                            <td>\s</td>
                                            <td align="center">任意一个空白字符(空格、换行符、换页符、回车符、字表符)</td>

                                        </tr>
                                        <tr>
                                            <td>\S</td>
                                            <td align="center">任意一个非空白字符</td>

                                        </tr>
                                        <tr>
                                            <td>\w</td>
                                            <td align="center">任意一个单词字符</td>

                                        </tr>
                                        <tr>
                                            <td>\W</td>
                                            <td align="center">任意个非单词字符</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <p>###显示不可打印的字符</p>
                                    <table>
                                        <thead>
                                        <tr><th>字符</th><th align="center">含义</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>\a</td>
                                            <td align="center">报警</td>

                                        </tr>
                                        <tr>
                                            <td>\b</td>
                                            <td align="center">退格</td>

                                        </tr>
                                        <tr>
                                            <td>\f</td>
                                            <td align="center">换页</td>

                                        </tr>
                                        <tr>
                                            <td>\n</td>
                                            <td align="center">换行</td>

                                        </tr>
                                        <tr>
                                            <td>\r</td>
                                            <td align="center">回车</td>

                                        </tr>
                                        <tr>
                                            <td>\t</td>
                                            <td align="center">字表符</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h2 id="括号字符"><a name="t11"></a>括号字符()</h2>
                                    <p>在正则表达式中小括号的作用主要有:</p>
                                    <ul>
                                        <li>改变限定符如（|、* 、^)的作用范围&nbsp;<br>如(my|your)baby，如果没有”()”，|将匹配的是要么是my，要么是yourbaby,有了小括号，匹配的就是mybaby或yourbaby。</li>
                                        <li>进行分组，便于反向引用</li>

                                    </ul>
                                    <h2 id="反向引用"><a name="t12"></a>反向引用</h2>
                                    <p>反向引用，就是依靠子表达式的”记忆”功能，匹配连续出现的字串或是字符。如(dqs)(pps)\1\2，表示匹配字符串dqsppsdqspps。在下面php应用中，我将详细展开学习反向引用。</p>
                                    <h2 id="模式修饰符"><a name="t13"></a>模式修饰符</h2>
                                    <p>模式修饰符的作用是设定模式，也就是正则表达式如何解释。php中主要模式如下表：</p>
                                    <table>
                                        <thead>
                                        <tr><th>修饰符</th><th align="center">说明</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>i</td>
                                            <td align="center">忽略大小写</td>

                                        </tr>
                                        <tr>
                                            <td>m</td>
                                            <td align="center">多文本模式</td>

                                        </tr>
                                        <tr>
                                            <td>s</td>
                                            <td align="center">单行文本模式</td>

                                        </tr>
                                        <tr>
                                            <td>x</td>
                                            <td align="center">忽略空白字符</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h1 id="正则表达式在php中应用"><a name="t14"></a>正则表达式在php中应用</h1>
                                    <h2 id="php中字符串匹配"><a name="t15"></a>php中字符串匹配</h2>
                                    <p>所谓的字符串匹配，言外之意就是判断一个字符串中，是否包含或是等于另一个字符串。如果不使用正则，我们可以使用php中提供了很多方法进行这样的判断。</p>
                                    <h3 id="不使用正则匹配"><a name="t16"></a>不使用正则匹配</h3>
                                    <ul>
                                        <li>strstr函数&nbsp;<br>string strstr ( string&nbsp;<span class="MathJax_Preview"><span class="MathJax_Preview"><span class="MathJax"><span id="MathJax-Span-1" class="math"><span id="MathJax-Span-2" class="mrow"><span id="MathJax-Span-3" class="mi">h<span id="MathJax-Span-4" class="mi">a<span id="MathJax-Span-5" class="mi">y<span id="MathJax-Span-6" class="mi">s<span id="MathJax-Span-7" class="mi">t<span id="MathJax-Span-8" class="mi">a<span id="MathJax-Span-9" class="mi">c<span id="MathJax-Span-10" class="mi">k<span id="MathJax-Span-11" class="mo">,<span id="MathJax-Span-12" class="mi">m<span id="MathJax-Span-13" class="mi">i<span id="MathJax-Span-14" class="mi">x<span id="MathJax-Span-15" class="mi">e<span id="MathJax-Span-16" class="mi">d</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>needle [, bool $before_needle = false ])&nbsp;<br></span></span></span>
                                            <ul>
                                                <li>注1：<span class="MathJax_Preview"><span id="MathJax-Element-3-Frame" class="MathJax"><span id="MathJax-Span-17" class="math"><span id="MathJax-Span-18" class="mrow"><span id="MathJax-Span-19" class="mi">h<span id="MathJax-Span-20" class="mi">a<span id="MathJax-Span-21" class="mi">y<span id="MathJax-Span-22" class="mi">s<span id="MathJax-Span-23" class="mi">t<span id="MathJax-Span-24" class="mi">a<span id="MathJax-Span-25" class="mi">c<span id="MathJax-Span-26" class="mi">k<span id="MathJax-Span-27" class="texatom"><span id="MathJax-Span-28" class="mrow"><span id="MathJax-Span-29" class="mo">是<span id="MathJax-Span-30" class="texatom"><span id="MathJax-Span-31" class="mrow"><span id="MathJax-Span-32" class="mo">当<span id="MathJax-Span-33" class="texatom"><span id="MathJax-Span-34" class="mrow"><span id="MathJax-Span-35" class="mo">事<span id="MathJax-Span-36" class="texatom"><span id="MathJax-Span-37" class="mrow"><span id="MathJax-Span-38" class="mo">字<span id="MathJax-Span-39" class="texatom"><span id="MathJax-Span-40" class="mrow"><span id="MathJax-Span-41" class="mo">符<span id="MathJax-Span-42" class="texatom"><span id="MathJax-Span-43" class="mrow"><span id="MathJax-Span-44" class="mo">串<span id="MathJax-Span-45" class="texatom"><span id="MathJax-Span-46" class="mrow"><span id="MathJax-Span-47" class="mo">，</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>needle是被查找的字符串。该函数区分大小写。</span></span></li>
                                                <li>注2：返回值是从needle开始到最后。</li>
                                                <li>注3：关于$needle，如果不是字符串，被当作整形来作为字符的序号来使用。</li>
                                                <li>注4：before_needle若为true,则返回前东西。</li>

                                            </ul>

                                        </li>
                                        <li>stristr函数与strstr函数相同，只是它不区分大小写</li>
                                        <li>strpo函数&nbsp;<br>int strpos ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-4-Frame" class="MathJax"><span id="MathJax-Span-48" class="math"><span id="MathJax-Span-49" class="mrow"><span id="MathJax-Span-50" class="mi">h<span id="MathJax-Span-51" class="mi">a<span id="MathJax-Span-52" class="mi">y<span id="MathJax-Span-53" class="mi">s<span id="MathJax-Span-54" class="mi">t<span id="MathJax-Span-55" class="mi">a<span id="MathJax-Span-56" class="mi">c<span id="MathJax-Span-57" class="mi">k<span id="MathJax-Span-58" class="mo">,<span id="MathJax-Span-59" class="mi">m<span id="MathJax-Span-60" class="mi">i<span id="MathJax-Span-61" class="mi">x<span id="MathJax-Span-62" class="mi">e<span id="MathJax-Span-63" class="mi">d</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>needle [, int $offset = 0 ] )&nbsp;<br>注1：可选的 offset 参数可以用来指定从 haystack 中的哪一个字符开始查找。返回的数字位置是相对于 haystack 的起始位置而言的。</span></span></li>
                                        <li>stripos -查找字符串<strong>首次出现</strong>的位置（<strong>不区分大小</strong>定）</li>
                                        <li>strrpos -计算指定字符串在目标字符串中<strong>最后一次出现</strong>的位置</li>
                                        <li>strripos -计算指定字符串在目标字符串中<strong>最后一次出现</strong>的位置（<strong>不区分大小写</strong>）</li>

                                    </ul>
                                    <h3 id="使用正则进行匹配"><a name="t17"></a>使用正则进行匹配</h3>
                                    <p>在php中，提供了preg_math()和preg_match_all函数进行正则匹配。关于这两个函数原型如下：</p>
                                    <pre name="code" class="prettyprint"><code class="hljs mel has-numbering"><span class="hljs-keyword"><br>int preg_match|preg_match_all ( <span class="hljs-keyword">string <span class="hljs-variable">$pattern , <span class="hljs-keyword">string <span class="hljs-variable">$subject [, array &amp;<span class="hljs-variable">$matches [, <span class="hljs-keyword">int <span class="hljs-variable">$flags = <span class="hljs-number">0 [, <span class="hljs-keyword">int <span class="hljs-variable">$offset = <span class="hljs-number">0 ]]] )</span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <p>搜索subject与pattern给定的正则表达式的一个匹配.&nbsp;<br>pattern:要搜索的模式，字符串类型。&nbsp;<br>subject :输入字符串。&nbsp;<br>matches:如果提供了参数matches，它将被填充为搜索结果。&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-5-Frame" class="MathJax"><span id="MathJax-Span-64" class="math"><span id="MathJax-Span-65" class="mrow"><span id="MathJax-Span-66" class="mi">m<span id="MathJax-Span-67" class="mi">a<span id="MathJax-Span-68" class="mi">t<span id="MathJax-Span-69" class="mi">c<span id="MathJax-Span-70" class="mi">h<span id="MathJax-Span-71" class="mi">e<span id="MathJax-Span-72" class="mi">s<span id="MathJax-Span-73" class="mo">[<span id="MathJax-Span-74" class="mn">0<span id="MathJax-Span-75" class="mo">]<span id="MathJax-Span-76" class="texatom"><span id="MathJax-Span-77" class="mrow"><span id="MathJax-Span-78" class="mo">将<span id="MathJax-Span-79" class="texatom"><span id="MathJax-Span-80" class="mrow"><span id="MathJax-Span-81" class="mo">包<span id="MathJax-Span-82" class="texatom"><span id="MathJax-Span-83" class="mrow"><span id="MathJax-Span-84" class="mo">含<span id="MathJax-Span-85" class="texatom"><span id="MathJax-Span-86" class="mrow"><span id="MathJax-Span-87" class="mo">完<span id="MathJax-Span-88" class="texatom"><span id="MathJax-Span-89" class="mrow"><span id="MathJax-Span-90" class="mo">整<span id="MathJax-Span-91" class="texatom"><span id="MathJax-Span-92" class="mrow"><span id="MathJax-Span-93" class="mo">模<span id="MathJax-Span-94" class="texatom"><span id="MathJax-Span-95" class="mrow"><span id="MathJax-Span-96" class="mo">式<span id="MathJax-Span-97" class="texatom"><span id="MathJax-Span-98" class="mrow"><span id="MathJax-Span-99" class="mo">匹<span id="MathJax-Span-100" class="texatom"><span id="MathJax-Span-101" class="mrow"><span id="MathJax-Span-102" class="mo">配<span id="MathJax-Span-103" class="texatom"><span id="MathJax-Span-104" class="mrow"><span id="MathJax-Span-105" class="mo">到<span id="MathJax-Span-106" class="texatom"><span id="MathJax-Span-107" class="mrow"><span id="MathJax-Span-108" class="mo">的<span id="MathJax-Span-109" class="texatom"><span id="MathJax-Span-110" class="mrow"><span id="MathJax-Span-111" class="mo">文<span id="MathJax-Span-112" class="texatom"><span id="MathJax-Span-113" class="mrow"><span id="MathJax-Span-114" class="mo">本<span id="MathJax-Span-115" class="texatom"><span id="MathJax-Span-116" class="mrow"><span id="MathJax-Span-117" class="mo">，</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>matches[1]将包含第一个捕获子组匹配到的文本，以此类推。&nbsp;<br>flags:flags可以被设置为以下标记值：PREG_OFFSET_CAPTURE 如果传递了这个标记，对于每一个出现的匹配返回时会附加字符串偏移量(相对于目标字符串的)。 注意：这会改变填充到matches参数的数组，使其每个元素成为一个由 第0个元素是匹配到的字符串，第1个元素是该匹配字符串 在目标字符串subject中的偏移量。&nbsp;<br>offset:通常，搜索从目标字符串的开始位置开始。可选参数 offset 用于 指定从目标字符串的某个未知开始搜索(单位是字节)。&nbsp;<br>返回值：preg_match()返回 pattern 的匹配次数。 它的值将是0次（不匹配）或1次，因为 preg_match()在第一次匹配后 将会停止搜索。 preg_match_all()不同于此，它会一直搜索subject直到到达结尾。 如果发生错误 preg_match()返回 FALSE。</span></span></p>
                                    <h3 id="实例"><a name="t18"></a>实例</h3>
                                    <ul>
                                        <li>实例1&nbsp;<br>判断字符串”<a href="http://blog.csdn.net/hsd2012">http://blog.csdn.net/hsd2012</a>“中是否包含csdn?&nbsp;<br>解法一（不适用正则）：&nbsp;<br>如果不适用正则，我们使用strstr或者strpos中任意一个都可以，在此，我将使用strstr函数，代码如下：</li>

                                    </ul>
                                    <pre name="code" class="prettyprint"><code class="hljs php has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012';
<span class="hljs-function"><span class="hljs-keyword">function <span class="hljs-title">checkStr1<span class="hljs-params">(<span class="hljs-variable">$str,<span class="hljs-variable">$str2)
{
    <span class="hljs-keyword">return strstr1(<span class="hljs-variable">$str,<span class="hljs-variable">$str2)?<span class="hljs-keyword">true:<span class="hljs-keyword">false;
}
<span class="hljs-keyword">echo checkStr(<span class="hljs-variable">$str,<span class="hljs-string">'csdn');</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <p>解法二：使用正则&nbsp;<br>因为我们只需要判断是否存在即可，所以选择preg_match。</p>
                                    <pre name="code" class="prettyprint"><code class="hljs php has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/csdn/';
<span class="hljs-function"><span class="hljs-keyword">function <span class="hljs-title">checkStr2<span class="hljs-params">(<span class="hljs-variable">$str,<span class="hljs-variable">$str2)
{
    <span class="hljs-keyword">return preg_match(<span class="hljs-variable">$str2,<span class="hljs-variable">$str)?<span class="hljs-keyword">true:<span class="hljs-keyword">false;
}
<span class="hljs-keyword">echo checkStr2(<span class="hljs-variable">$str,<span class="hljs-variable">$pattern);</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <ul>
                                        <li>实例2（考察<strong>单词定界符</strong>）&nbsp;<br>判断字符串”I am a good boy”中是否包含单词go&nbsp;<br>首先判断是单词，而不是字符串，因此比较的时候，需要比较是否包含’ go ‘，即在字符串go前后有一个空格。&nbsp;<br>解析：如果使用非正则比较，只需要调用上面的checkStr1()函数即可，注意，第二个参数前后要加一个空格,即’ go ‘。如果使用正则，&nbsp;<br>我们可以考虑使用单词定界符\b，那么$pattern=’/\bgo\b/’;然后调用checkStr2函数即可.</li>
                                        <li>例3（考察<strong>反向引用</strong>)&nbsp;<br>判断字符串”I am a good boy”中是否包含3个相同的字母&nbsp;<br>解析：此时，如果我们不使用正则，将会很难判断，因为字母太多了，我们不可能去将所有字母分别与该字符串比较，那样工作量也比较大。这时候涉及到了正在的反向引用。在php正则表达式中，通过\n，来表示第n次匹配到的结果。如\5代表第五次匹配到的结果。那么本题的<code>$pattern='/(\w).*\1.*\1/';</code>&nbsp;<br>主要注意的是，在使用反向匹配的时候都需要使用(),反向匹配时，匹配()里面出现的字符或字符串。</li>

                                    </ul>
                                    <h2 id="php中字符串替换"><a name="t19"></a>php中字符串替换</h2>
                                    <h3 id="不使用正则"><a name="t20"></a>不使用正则</h3>
                                    <p>php中当替换字符串的时候，如果不适用正则，我们通常使用substr、mb_substr、str_replace、substr_replace关于这几个函数区别如下表。</p>
                                    <table>
                                        <thead>
                                        <tr><th>函数符</th><th align="center">功能</th><th align="center">描述</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>str_replace(find,replace,string,count)</td>
                                            <td align="center">使用一个字符串替换字符串中的另一些字符。</td>
                                            <td align="center">find 必需。规定要查找的值。replace 必需。规定替换 find 中的值的值。string 必需。规定被搜索的字符串。count 可选。一个变量，对替换数进行计数。</td>

                                        </tr>
                                        <tr>
                                            <td>substr_replace(string,replacement,start,length)</td>
                                            <td align="center">把字符串的一部分替换为另一个字符串。适合用于替换自定位置的字符串。</td>
                                            <td align="center">string 必需。规定要检查的字符串。replacement 必需。规定要插入的字符串。start 必需。规定在字符串的何处开始替换。</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h3 id="使用正则"><a name="t21"></a>使用正则</h3>
                                    <p>如果使用正则替换，php中提供了preg_replace _callback和preg_replace 函数，preg_replace 原型如下：&nbsp;<br>mixed preg_replace ( mixed&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-6-Frame" class="MathJax"><span id="MathJax-Span-118" class="math"><span id="MathJax-Span-119" class="mrow"><span id="MathJax-Span-120" class="mi">p<span id="MathJax-Span-121" class="mi">a<span id="MathJax-Span-122" class="mi">t<span id="MathJax-Span-123" class="mi">t<span id="MathJax-Span-124" class="mi">e<span id="MathJax-Span-125" class="mi">r<span id="MathJax-Span-126" class="mi">n<span id="MathJax-Span-127" class="mo">,<span id="MathJax-Span-128" class="mi">m<span id="MathJax-Span-129" class="mi">i<span id="MathJax-Span-130" class="mi">x<span id="MathJax-Span-131" class="mi">e<span id="MathJax-Span-132" class="mi">d</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>replacement , mixed&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-7-Frame" class="MathJax"><span id="MathJax-Span-133" class="math"><span id="MathJax-Span-134" class="mrow"><span id="MathJax-Span-135" class="mi">s<span id="MathJax-Span-136" class="mi">u<span id="MathJax-Span-137" class="mi">b<span id="MathJax-Span-138" class="mi">j<span id="MathJax-Span-139" class="mi">e<span id="MathJax-Span-140" class="mi">c<span id="MathJax-Span-141" class="mi">t<span id="MathJax-Span-142" class="mo">[<span id="MathJax-Span-143" class="mo">,<span id="MathJax-Span-144" class="mi">i<span id="MathJax-Span-145" class="mi">n<span id="MathJax-Span-146" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span></span></span>limit = -1 [, int &amp;<span class="MathJax_Preview"><span id="MathJax-Element-8-Frame" class="MathJax"><span id="MathJax-Span-147" class="math"><span id="MathJax-Span-148" class="mrow"><span id="MathJax-Span-149" class="mi">c<span id="MathJax-Span-150" class="mi">o<span id="MathJax-Span-151" class="mi">u<span id="MathJax-Span-152" class="mi">n<span id="MathJax-Span-153" class="mi">t<span id="MathJax-Span-154" class="mo">]<span id="MathJax-Span-155" class="mo">]<span id="MathJax-Span-156" class="mo">)<span id="MathJax-Span-157" class="texatom"><span id="MathJax-Span-158" class="mrow"><span id="MathJax-Span-159" class="mo">函<span id="MathJax-Span-160" class="texatom"><span id="MathJax-Span-161" class="mrow"><span id="MathJax-Span-162" class="mo">数<span id="MathJax-Span-163" class="texatom"><span id="MathJax-Span-164" class="mrow"><span id="MathJax-Span-165" class="mo">功<span id="MathJax-Span-166" class="texatom"><span id="MathJax-Span-167" class="mrow"><span id="MathJax-Span-168" class="mo">能<span id="MathJax-Span-169" class="texatom"><span id="MathJax-Span-170" class="mrow"><span id="MathJax-Span-171" class="mo">描<span id="MathJax-Span-172" class="texatom"><span id="MathJax-Span-173" class="mrow"><span id="MathJax-Span-174" class="mo">述<span id="MathJax-Span-175" class="texatom"><span id="MathJax-Span-176" class="mrow"><span id="MathJax-Span-177" class="mo">：<span id="MathJax-Span-178" class="texatom"><span id="MathJax-Span-179" class="mrow"><span id="MathJax-Span-180" class="mo">在<span id="MathJax-Span-181" class="texatom"><span id="MathJax-Span-182" class="mrow"><span id="MathJax-Span-183" class="mo">字<span id="MathJax-Span-184" class="texatom"><span id="MathJax-Span-185" class="mrow"><span id="MathJax-Span-186" class="mo">符<span id="MathJax-Span-187" class="texatom"><span id="MathJax-Span-188" class="mrow"><span id="MathJax-Span-189" class="mo">串</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>subject中，查找<span class="MathJax_Preview"><span id="MathJax-Element-9-Frame" class="MathJax"><span id="MathJax-Span-190" class="math"><span id="MathJax-Span-191" class="mrow"><span id="MathJax-Span-192" class="mi">p<span id="MathJax-Span-193" class="mi">a<span id="MathJax-Span-194" class="mi">t<span id="MathJax-Span-195" class="mi">t<span id="MathJax-Span-196" class="mi">e<span id="MathJax-Span-197" class="mi">r<span id="MathJax-Span-198" class="mi">n<span id="MathJax-Span-199" class="mo">,<span id="MathJax-Span-200" class="texatom"><span id="MathJax-Span-201" class="mrow"><span id="MathJax-Span-202" class="mo">然<span id="MathJax-Span-203" class="texatom"><span id="MathJax-Span-204" class="mrow"><span id="MathJax-Span-205" class="mo">后<span id="MathJax-Span-206" class="texatom"><span id="MathJax-Span-207" class="mrow"><span id="MathJax-Span-208" class="mo">使<span id="MathJax-Span-209" class="texatom"><span id="MathJax-Span-210" class="mrow"><span id="MathJax-Span-211" class="mo">用</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>replacement 去替换，如果有<span class="MathJax_Preview"><span id="MathJax-Element-10-Frame" class="MathJax"><span id="MathJax-Span-212" class="math"><span id="MathJax-Span-213" class="mrow"><span id="MathJax-Span-214" class="mi">l<span id="MathJax-Span-215" class="mi">i<span id="MathJax-Span-216" class="mi">m<span id="MathJax-Span-217" class="mi">i<span id="MathJax-Span-218" class="mi">t<span id="MathJax-Span-219" class="texatom"><span id="MathJax-Span-220" class="mrow"><span id="MathJax-Span-221" class="mo">则<span id="MathJax-Span-222" class="texatom"><span id="MathJax-Span-223" class="mrow"><span id="MathJax-Span-224" class="mo">代<span id="MathJax-Span-225" class="texatom"><span id="MathJax-Span-226" class="mrow"><span id="MathJax-Span-227" class="mo">表<span id="MathJax-Span-228" class="texatom"><span id="MathJax-Span-229" class="mrow"><span id="MathJax-Span-230" class="mo">限<span id="MathJax-Span-231" class="texatom"><span id="MathJax-Span-232" class="mrow"><span id="MathJax-Span-233" class="mo">制<span id="MathJax-Span-234" class="texatom"><span id="MathJax-Span-235" class="mrow"><span id="MathJax-Span-236" class="mo">替<span id="MathJax-Span-237" class="texatom"><span id="MathJax-Span-238" class="mrow"><span id="MathJax-Span-239" class="mo">换<span id="MathJax-Span-240" class="mi">l<span id="MathJax-Span-241" class="mi">i<span id="MathJax-Span-242" class="mi">m<span id="MathJax-Span-243" class="mi">i<span id="MathJax-Span-244" class="mi">t<span id="MathJax-Span-245" class="texatom"><span id="MathJax-Span-246" class="mrow"><span id="MathJax-Span-247" class="mo">次<span id="MathJax-Span-248" class="texatom"><span id="MathJax-Span-249" class="mrow"><span id="MathJax-Span-250" class="mo">。<span id="MathJax-Span-251" class="mi">p<span id="MathJax-Span-252" class="mi">r<span id="MathJax-Span-253" class="mi">e<span id="MathJax-Span-254" class="msubsup"><span id="MathJax-Span-255" class="mi">g<span id="MathJax-Span-256" class="mi">r<span id="MathJax-Span-257" class="mi">e<span id="MathJax-Span-258" class="mi">p<span id="MathJax-Span-259" class="mi">l<span id="MathJax-Span-260" class="mi">a<span id="MathJax-Span-261" class="mi">c<span id="MathJax-Span-262" class="msubsup"><span id="MathJax-Span-263" class="mi">e<span id="MathJax-Span-264" class="mi">c<span id="MathJax-Span-265" class="mi">a<span id="MathJax-Span-266" class="mi">l<span id="MathJax-Span-267" class="mi">l<span id="MathJax-Span-268" class="mi">b<span id="MathJax-Span-269" class="mi">a<span id="MathJax-Span-270" class="mi">c<span id="MathJax-Span-271" class="mi">k<span id="MathJax-Span-272" class="texatom"><span id="MathJax-Span-273" class="mrow"><span id="MathJax-Span-274" class="mo">与<span id="MathJax-Span-275" class="mi">p<span id="MathJax-Span-276" class="mi">r<span id="MathJax-Span-277" class="mi">e<span id="MathJax-Span-278" class="msubsup"><span id="MathJax-Span-279" class="mi">g<span id="MathJax-Span-280" class="mi">r<span id="MathJax-Span-281" class="mi">e<span id="MathJax-Span-282" class="mi">p<span id="MathJax-Span-283" class="mi">l<span id="MathJax-Span-284" class="mi">a<span id="MathJax-Span-285" class="mi">c<span id="MathJax-Span-286" class="mi">e<span id="MathJax-Span-287" class="texatom"><span id="MathJax-Span-288" class="mrow"><span id="MathJax-Span-289" class="mo">功<span id="MathJax-Span-290" class="texatom"><span id="MathJax-Span-291" class="mrow"><span id="MathJax-Span-292" class="mo">能<span id="MathJax-Span-293" class="texatom"><span id="MathJax-Span-294" class="mrow"><span id="MathJax-Span-295" class="mo">相<span id="MathJax-Span-296" class="texatom"><span id="MathJax-Span-297" class="mrow"><span id="MathJax-Span-298" class="mo">识<span id="MathJax-Span-299" class="texatom"><span id="MathJax-Span-300" class="mrow"><span id="MathJax-Span-301" class="mo">，<span id="MathJax-Span-302" class="texatom"><span id="MathJax-Span-303" class="mrow"><span id="MathJax-Span-304" class="mo">不<span id="MathJax-Span-305" class="texatom"><span id="MathJax-Span-306" class="mrow"><span id="MathJax-Span-307" class="mo">同<span id="MathJax-Span-308" class="texatom"><span id="MathJax-Span-309" class="mrow"><span id="MathJax-Span-310" class="mo">的<span id="MathJax-Span-311" class="texatom"><span id="MathJax-Span-312" class="mrow"><span id="MathJax-Span-313" class="mo">是<span id="MathJax-Span-314" class="mi">p<span id="MathJax-Span-315" class="mi">r<span id="MathJax-Span-316" class="mi">e<span id="MathJax-Span-317" class="msubsup"><span id="MathJax-Span-318" class="mi">g<span id="MathJax-Span-319" class="mi">r<span id="MathJax-Span-320" class="mi">e<span id="MathJax-Span-321" class="mi">p<span id="MathJax-Span-322" class="mi">l<span id="MathJax-Span-323" class="mi">a<span id="MathJax-Span-324" class="mi">c<span id="MathJax-Span-325" class="msubsup"><span id="MathJax-Span-326" class="mi">e<span id="MathJax-Span-327" class="mi">b<span id="MathJax-Span-328" class="mi">a<span id="MathJax-Span-329" class="mi">c<span id="MathJax-Span-330" class="mi">k<span id="MathJax-Span-331" class="texatom"><span id="MathJax-Span-332" class="mrow"><span id="MathJax-Span-333" class="mo">使<span id="MathJax-Span-334" class="texatom"><span id="MathJax-Span-335" class="mrow"><span id="MathJax-Span-336" class="mo">用<span id="MathJax-Span-337" class="texatom"><span id="MathJax-Span-338" class="mrow"><span id="MathJax-Span-339" class="mo">一<span id="MathJax-Span-340" class="texatom"><span id="MathJax-Span-341" class="mrow"><span id="MathJax-Span-342" class="mo">个<span id="MathJax-Span-343" class="texatom"><span id="MathJax-Span-344" class="mrow"><span id="MathJax-Span-345" class="mo">回<span id="MathJax-Span-346" class="texatom"><span id="MathJax-Span-347" class="mrow"><span id="MathJax-Span-348" class="mo">调<span id="MathJax-Span-349" class="texatom"><span id="MathJax-Span-350" class="mrow"><span id="MathJax-Span-351" class="mo">函<span id="MathJax-Span-352" class="texatom"><span id="MathJax-Span-353" class="mrow"><span id="MathJax-Span-354" class="mo">数<span id="MathJax-Span-355" class="mi">c<span id="MathJax-Span-356" class="mi">a<span id="MathJax-Span-357" class="mi">l<span id="MathJax-Span-358" class="mi">l<span id="MathJax-Span-359" class="mi">b<span id="MathJax-Span-360" class="mi">a<span id="MathJax-Span-361" class="mi">c<span id="MathJax-Span-362" class="mi">k<span id="MathJax-Span-363" class="texatom"><span id="MathJax-Span-364" class="mrow"><span id="MathJax-Span-365" class="mo">来<span id="MathJax-Span-366" class="texatom"><span id="MathJax-Span-367" class="mrow"><span id="MathJax-Span-368" class="mo">代<span id="MathJax-Span-369" class="texatom"><span id="MathJax-Span-370" class="mrow"><span id="MathJax-Span-371" class="mo">替<span id="MathJax-Span-372" class="mi">r<span id="MathJax-Span-373" class="mi">e<span id="MathJax-Span-374" class="mi">p<span id="MathJax-Span-375" class="mi">l<span id="MathJax-Span-376" class="mi">a<span id="MathJax-Span-377" class="mi">c<span id="MathJax-Span-378" class="mi">e<span id="MathJax-Span-379" class="mi">m<span id="MathJax-Span-380" class="mi">e<span id="MathJax-Span-381" class="mi">n<span id="MathJax-Span-382" class="mi">t<span id="MathJax-Span-383" class="mo">.<span id="MathJax-Span-384" class="mo">−<span id="MathJax-Span-385" class="texatom"><span id="MathJax-Span-386" class="mrow"><span id="MathJax-Span-387" class="mo">例<span id="MathJax-Span-388" class="mn">1<span id="MathJax-Span-389" class="texatom"><span id="MathJax-Span-390" class="mrow"><span id="MathJax-Span-391" class="mo">将<span id="MathJax-Span-392" class="texatom"><span id="MathJax-Span-393" class="mrow"><span id="MathJax-Span-394" class="mo">字<span id="MathJax-Span-395" class="texatom"><span id="MathJax-Span-396" class="mrow"><span id="MathJax-Span-397" class="mo">符<span id="MathJax-Span-398" class="texatom"><span id="MathJax-Span-399" class="mrow"><span id="MathJax-Span-400" class="mo">串<span id="MathJax-Span-401" class="mo">”<span id="MathJax-Span-402" class="mi">h<span id="MathJax-Span-403" class="mi">e<span id="MathJax-Span-404" class="mi">l<span id="MathJax-Span-405" class="mi">l<span id="MathJax-Span-406" class="mi">o<span id="MathJax-Span-407" class="mo">,<span id="MathJax-Span-408" class="texatom"><span id="MathJax-Span-409" class="mrow"><span id="MathJax-Span-410" class="mo">中<span id="MathJax-Span-411" class="texatom"><span id="MathJax-Span-412" class="mrow"><span id="MathJax-Span-413" class="mo">国<span id="MathJax-Span-414" class="mo">”<span id="MathJax-Span-415" class="texatom"><span id="MathJax-Span-416" class="mrow"><span id="MathJax-Span-417" class="mo">中<span id="MathJax-Span-418" class="texatom"><span id="MathJax-Span-419" class="mrow"><span id="MathJax-Span-420" class="mo">的<span id="MathJax-Span-421" class="mi">h<span id="MathJax-Span-422" class="mi">e<span id="MathJax-Span-423" class="mi">l<span id="MathJax-Span-424" class="mi">l<span id="MathJax-Span-425" class="mi">o<span id="MathJax-Span-426" class="texatom"><span id="MathJax-Span-427" class="mrow"><span id="MathJax-Span-428" class="mo">替<span id="MathJax-Span-429" class="texatom"><span id="MathJax-Span-430" class="mrow"><span id="MathJax-Span-431" class="mo">换<span id="MathJax-Span-432" class="msup"><span id="MathJax-Span-433" class="texatom"><span id="MathJax-Span-434" class="mrow"><span id="MathJax-Span-435" class="mo">为<span id="MathJax-Span-436" class="mo">′<span id="MathJax-Span-437" class="texatom"><span id="MathJax-Span-438" class="mrow"><span id="MathJax-Span-439" class="mo">你<span id="MathJax-Span-440" class="msup"><span id="MathJax-Span-441" class="texatom"><span id="MathJax-Span-442" class="mrow"><span id="MathJax-Span-443" class="mo">好<span id="MathJax-Span-444" class="mo">′<span id="MathJax-Span-445" class="mo">;<span id="MathJax-Span-446" class="texatom"><span id="MathJax-Span-447" class="mrow"><span id="MathJax-Span-448" class="mo">如<span id="MathJax-Span-449" class="texatom"><span id="MathJax-Span-450" class="mrow"><span id="MathJax-Span-451" class="mo">果<span id="MathJax-Span-452" class="texatom"><span id="MathJax-Span-453" class="mrow"><span id="MathJax-Span-454" class="mo">不<span id="MathJax-Span-455" class="texatom"><span id="MathJax-Span-456" class="mrow"><span id="MathJax-Span-457" class="mo">是<span id="MathJax-Span-458" class="texatom"><span id="MathJax-Span-459" class="mrow"><span id="MathJax-Span-460" class="mo">用<span id="MathJax-Span-461" class="texatom"><span id="MathJax-Span-462" class="mrow"><span id="MathJax-Span-463" class="mo">正<span id="MathJax-Span-464" class="texatom"><span id="MathJax-Span-465" class="mrow"><span id="MathJax-Span-466" class="mo">则<span id="MathJax-Span-467" class="mo">:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str=’hello,中国’;&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-11-Frame" class="MathJax"><span id="MathJax-Span-468" class="math"><span id="MathJax-Span-469" class="mrow"><span id="MathJax-Span-470" class="mi">s<span id="MathJax-Span-471" class="mi">t<span id="MathJax-Span-472" class="mi">r<span id="MathJax-Span-473" class="mo">=<span id="MathJax-Span-474" class="mi">s<span id="MathJax-Span-475" class="mi">t<span id="MathJax-Span-476" class="msubsup"><span id="MathJax-Span-477" class="mi">r<span id="MathJax-Span-478" class="mi">r<span id="MathJax-Span-479" class="mi">e<span id="MathJax-Span-480" class="mi">p<span id="MathJax-Span-481" class="mi">l<span id="MathJax-Span-482" class="mi">a<span id="MathJax-Span-483" class="mi">c<span id="MathJax-Span-484" class="mi">e<span id="MathJax-Span-485" class="msup"><span id="MathJax-Span-486" class="mo">(<span id="MathJax-Span-487" class="mo">′<span id="MathJax-Span-488" class="mi">h<span id="MathJax-Span-489" class="mi">e<span id="MathJax-Span-490" class="mi">l<span id="MathJax-Span-491" class="mi">l<span id="MathJax-Span-492" class="msup"><span id="MathJax-Span-493" class="mi">o<span id="MathJax-Span-494" class="mo">′<span id="MathJax-Span-495" class="msup"><span id="MathJax-Span-496" class="mo">,<span id="MathJax-Span-497" class="mo">′<span id="MathJax-Span-498" class="texatom"><span id="MathJax-Span-499" class="mrow"><span id="MathJax-Span-500" class="mo">你<span id="MathJax-Span-501" class="msup"><span id="MathJax-Span-502" class="texatom"><span id="MathJax-Span-503" class="mrow"><span id="MathJax-Span-504" class="mo">好<span id="MathJax-Span-505" class="mo">′<span id="MathJax-Span-506" class="mo">,</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str)&nbsp;<br>或是使用<span class="MathJax_Preview"><span id="MathJax-Element-12-Frame" class="MathJax"><span id="MathJax-Span-507" class="math"><span id="MathJax-Span-508" class="mrow"><span id="MathJax-Span-509" class="mi">s<span id="MathJax-Span-510" class="mi">t<span id="MathJax-Span-511" class="mi">r<span id="MathJax-Span-512" class="mo">=<span id="MathJax-Span-513" class="mi">s<span id="MathJax-Span-514" class="mi">u<span id="MathJax-Span-515" class="mi">b<span id="MathJax-Span-516" class="mi">s<span id="MathJax-Span-517" class="mi">t<span id="MathJax-Span-518" class="msubsup"><span id="MathJax-Span-519" class="mi">r<span id="MathJax-Span-520" class="mi">r<span id="MathJax-Span-521" class="mi">e<span id="MathJax-Span-522" class="mi">p<span id="MathJax-Span-523" class="mi">l<span id="MathJax-Span-524" class="mi">a<span id="MathJax-Span-525" class="mi">c<span id="MathJax-Span-526" class="mi">e<span id="MathJax-Span-527" class="mo">(</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str,’你好’,0,5)&nbsp;<br>使用正则&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-13-Frame" class="MathJax"><span id="MathJax-Span-528" class="math"><span id="MathJax-Span-529" class="mrow"><span id="MathJax-Span-530" class="mi">p<span id="MathJax-Span-531" class="mi">a<span id="MathJax-Span-532" class="mi">t<span id="MathJax-Span-533" class="mi">t<span id="MathJax-Span-534" class="mi">e<span id="MathJax-Span-535" class="mi">r<span id="MathJax-Span-536" class="mi">n<span id="MathJax-Span-537" class="msup"><span id="MathJax-Span-538" class="mo">=<span id="MathJax-Span-539" class="mo">′<span id="MathJax-Span-540" class="texatom"><span id="MathJax-Span-541" class="mrow"><span id="MathJax-Span-542" class="mo">/<span id="MathJax-Span-543" class="mi">h<span id="MathJax-Span-544" class="mi">e<span id="MathJax-Span-545" class="mi">l<span id="MathJax-Span-546" class="mi">l<span id="MathJax-Span-547" class="mi">o<span id="MathJax-Span-548" class="msup"><span id="MathJax-Span-549" class="texatom"><span id="MathJax-Span-550" class="mrow"><span id="MathJax-Span-551" class="mo">/<span id="MathJax-Span-552" class="mo">′<span id="MathJax-Span-553" class="mo">;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str=preg_replace (<span class="MathJax_Preview"><span id="MathJax-Element-14-Frame" class="MathJax"><span id="MathJax-Span-554" class="math"><span id="MathJax-Span-555" class="mrow"><span id="MathJax-Span-556" class="mi">p<span id="MathJax-Span-557" class="mi">a<span id="MathJax-Span-558" class="mi">t<span id="MathJax-Span-559" class="mi">t<span id="MathJax-Span-560" class="mi">e<span id="MathJax-Span-561" class="mi">r<span id="MathJax-Span-562" class="mi">n<span id="MathJax-Span-563" class="msup"><span id="MathJax-Span-564" class="mo">,<span id="MathJax-Span-565" class="mo">′<span id="MathJax-Span-566" class="texatom"><span id="MathJax-Span-567" class="mrow"><span id="MathJax-Span-568" class="mo">你<span id="MathJax-Span-569" class="msup"><span id="MathJax-Span-570" class="texatom"><span id="MathJax-Span-571" class="mrow"><span id="MathJax-Span-572" class="mo">好<span id="MathJax-Span-573" class="mo">′<span id="MathJax-Span-574" class="mo">,</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str);&nbsp;<br>- 例2&nbsp;<br>去除字符串”gawwenngeeojjgegop”中连续相同的字母</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'gawwenngeeojjgegop';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/(.)\1/';
<span class="hljs-variable">$str=preg_replace(<span class="hljs-variable">$pattern,<span class="hljs-string">'',<span class="hljs-variable">$str);</span></span></span></span></span></span></span></span></code></pre>
                                    <p>解析：当然这样可能会遇到，当第一次去除了重复了字符串后，又出来重复的字符串。如字符串味’gewwenngeeojjgegop’,针对这中问题，当然，这样的话，通过判断，继续替换下去。</p>
                                    <ul>
                                        <li>例3&nbsp;<br>将字符串中”age13gegep3iorji65k65k”;中出现的连续两个数字改为第二个数字，如字符串中13被改为3</li>

                                    </ul>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'age13gegep3iorji65k65k';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/(\d)(\d)/';
<span class="hljs-variable">$str=preg_replace(<span class="hljs-variable">$pattern,<span class="hljs-string">'$2', <span class="hljs-variable">$str);</span></span></span></span></span></span></span></span></code></pre>
                                    <p>解析：$n在正则表达式外使用反向引用。n代表第几次匹配到的结果。</p>
                                    <h2 id="php中字符串分割"><a name="t22"></a>php中字符串分割</h2>
                                    <h3 id="不适用正则"><a name="t23"></a>不适用正则</h3>
                                    <p>php提供了explode函数去分割字符串，与其对应的是implode。关于explode原型如下：&nbsp;<br>array explode ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-15-Frame" class="MathJax"><span id="MathJax-Span-575" class="math"><span id="MathJax-Span-576" class="mrow"><span id="MathJax-Span-577" class="mi">d<span id="MathJax-Span-578" class="mi">e<span id="MathJax-Span-579" class="mi">l<span id="MathJax-Span-580" class="mi">i<span id="MathJax-Span-581" class="mi">m<span id="MathJax-Span-582" class="mi">i<span id="MathJax-Span-583" class="mi">t<span id="MathJax-Span-584" class="mi">e<span id="MathJax-Span-585" class="mi">r<span id="MathJax-Span-586" class="mo">,<span id="MathJax-Span-587" class="mi">s<span id="MathJax-Span-588" class="mi">t<span id="MathJax-Span-589" class="mi">r<span id="MathJax-Span-590" class="mi">i<span id="MathJax-Span-591" class="mi">n<span id="MathJax-Span-592" class="mi">g</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>string [, int $limit ] )&nbsp;<br>delimiter：边界上的分隔字符。&nbsp;<br>string：输入的字符串。&nbsp;<br>limit：如果设置了 limit 参数并且是正数，则返回的数组包含最多 limit 个元素，而最后那个元素将包含 string 的剩余部分。如果 limit 参数是负数，则返回除了最后的 -limit 个元素外的所有元素。如果 limit 是 0，则会被当做 1。</span></span></p>
                                    <h3 id="使用正则-1"><a name="t24"></a>使用正则</h3>
                                    <p>关于通过正则表达式进行字符串分割，php提供了split、preg_split 函数。preg_split() 函数，通常是比 split() 更快的替代方案。&nbsp;<br>array preg_split ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-16-Frame" class="MathJax"><span id="MathJax-Span-593" class="math"><span id="MathJax-Span-594" class="mrow"><span id="MathJax-Span-595" class="mi">p<span id="MathJax-Span-596" class="mi">a<span id="MathJax-Span-597" class="mi">t<span id="MathJax-Span-598" class="mi">t<span id="MathJax-Span-599" class="mi">e<span id="MathJax-Span-600" class="mi">r<span id="MathJax-Span-601" class="mi">n<span id="MathJax-Span-602" class="mo">,<span id="MathJax-Span-603" class="mi">s<span id="MathJax-Span-604" class="mi">t<span id="MathJax-Span-605" class="mi">r<span id="MathJax-Span-606" class="mi">i<span id="MathJax-Span-607" class="mi">n<span id="MathJax-Span-608" class="mi">g</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>subject [, int&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-17-Frame" class="MathJax"><span id="MathJax-Span-609" class="math"><span id="MathJax-Span-610" class="mrow"><span id="MathJax-Span-611" class="mi">l<span id="MathJax-Span-612" class="mi">i<span id="MathJax-Span-613" class="mi">m<span id="MathJax-Span-614" class="mi">i<span id="MathJax-Span-615" class="mi">t<span id="MathJax-Span-616" class="mo">=<span id="MathJax-Span-617" class="mo">−<span id="MathJax-Span-618" class="mn">1<span id="MathJax-Span-619" class="mo">[<span id="MathJax-Span-620" class="mo">,<span id="MathJax-Span-621" class="mi">i<span id="MathJax-Span-622" class="mi">n<span id="MathJax-Span-623" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>flags = 0 ]] )</span></span></span></span></p>
                                    <ul>
                                        <li>例题&nbsp;<br>将字符串 ‘<a href="http://blog.csdn.net/hsd2012/article/details/51152810">http://blog.csdn.net/hsd2012/article/details/51152810</a>‘按照’/’进行分割&nbsp;<br>解法一：</li>

                                    </ul>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012/article/details/51152810';
<span class="hljs-variable">$str=explode(<span class="hljs-string">'/', <span class="hljs-variable">$str);</span></span></span></span></span></code></pre>
                                    <p>解法二：</p>
                                    <pre name="code" class="prettyprint"><code class="hljs php has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'http://blog.csdn.net/hsd2012/article/details/51152810';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/\//';  <span class="hljs-comment">/*因为/为特殊字符，需要转移*/
<span class="hljs-variable">$str=preg_split (<span class="hljs-variable">$pattern, <span class="hljs-variable">$str);</span></span></span></span></span></span></span></span></code></pre>
                                    <h2 id="php中贪婪匹配与惰性匹配">php中贪婪匹配与惰性匹配</h2>
                                    <ul>
                                        <li>贪婪匹配：就是匹配尽可能多的字符。&nbsp;<br>比如，正则表达式中m.*n，它将匹配最长以m开始，n结尾的字符串。如果用它来搜索manmpndegenc的话，它将匹配到的字符串是manmpndegen而非man。可以这样想，当匹配到m的时候，它将从后面往前匹配字符n。</li>
                                        <li>懒惰匹配：就是匹配尽可能少的字符。&nbsp;<br>有的时候，我们需要并不是去贪婪匹配，而是尽可能少的去匹配。这时候，就需要将其转为惰性匹配。怎样将一个贪婪匹配转为惰性匹配呢？只需要在其后面添加一个”？”即可。如m.*?n将匹配manmpndegenc，匹配到的字符串是man。</li>

                                    </ul>
                                    <table>
                                        <thead>
                                        <tr><th>函数符</th><th align="center">描述</th></tr>

                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>*?</td>
                                            <td align="center">零次或多次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>+?</td>
                                            <td align="center">一次或多次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>??</td>
                                            <td align="center">0次或1次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>{n,}?</td>
                                            <td align="center">至少n次，但尽可能少的匹配</td>

                                        </tr>
                                        <tr>
                                            <td>{n,m}?</td>
                                            <td align="center">n到m次 ，但尽可能少的匹配</td>

                                        </tr>

                                        </tbody>

                                    </table>
                                    <h2 id="php正则表达式之回溯与固态分组"><a name="t26"></a>php正则表达式之回溯与固态分组</h2>
                                    <h3 id="回溯"><a name="t27"></a>回溯</h3>
                                    <p>首先我们需要清楚什么是回溯，回溯就像是在走岔路口，当遇到岔路的时候就先在每个路口做一个标记。如果走了死路，就可以照原路返回，直到遇见之前所做过的标记，标记着还未尝试过的道路。如果那条路也走不能，可以继续返回，找到下一个标记，如此重复，直到找到出路，或者直到完成所有没有尝试过的路。首先我们看例题</p>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'aageacwgewcaw';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/a\w*c/i';
<span class="hljs-variable">$str=preg_match(<span class="hljs-variable">$pattern, <span class="hljs-variable">$str);</span></span></span></span></span></span></span></code></pre>
                                    <p>看到上面的程序，可能都清楚是什么意思，就是匹配$str是否包含这样一个由”a+0个或多个字母+c”不区分大小写的字符串。但是至于程序怎样去匹配的呢？匹配的过程中，回溯了多少次呢？</p>
                                    <table>
                                        <thead>
                                        <tr><th>匹配过程</th><th align="center">接下来操作描述</th></tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td>‘a\w*c’中a匹配到’aageacwgewcaw’中第一个字符a</td>
                                            <td align="center">\w进行下一个字符匹配</td>
                                        </tr>
                                        <tr>
                                            <td>因为\w是贪婪匹配，会一直匹配到’aageacwgewcaw’中最后一个字符w</td>
                                            <td align="center">c进行下一个字符匹配时</td>
                                        </tr>
                                        <tr>
                                            <td>‘a\w*c’中c发现没有可以匹配的</td>
                                            <td align="center">于是\w匹配进行第一次回溯，匹配到倒数第二个字符a</td>
                                        </tr>
                                        <tr>
                                            <td>‘a\w*c’中c发现还是没有可以匹配的</td>
                                            <td align="center">于是\w匹配进行第二次回溯，匹配到倒数第三个字符c</td>
                                        </tr>
                                        <tr>
                                            <td>‘a\w*c’中c匹配成功</td>
                                            <td align="center">匹配结束返回结果</td>
                                        </tr>
                                        </tbody>
                                    </table>
                                    <p>现在，如果我们将<span class="MathJax_Preview"><span id="MathJax-Element-18-Frame" class="MathJax"><span id="MathJax-Span-624" class="math"><span id="MathJax-Span-625" class="mrow"><span id="MathJax-Span-626" class="mi">p<span id="MathJax-Span-627" class="mi">a<span id="MathJax-Span-628" class="mi">t<span id="MathJax-Span-629" class="mi">t<span id="MathJax-Span-630" class="mi">e<span id="MathJax-Span-631" class="mi">r<span id="MathJax-Span-632" class="mi">n<span id="MathJax-Span-633" class="texatom"><span id="MathJax-Span-634" class="mrow"><span id="MathJax-Span-635" class="mo">改<span id="MathJax-Span-636" class="texatom"><span id="MathJax-Span-637" class="mrow"><span id="MathJax-Span-638" class="mo">为</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>pattern=’/a\w*?c/i’;又会回溯多少次呢？正确答案是回溯四次。</span></span></p>
                                    <h3 id="固态分组"><a name="t28"></a>固态分组</h3>
                                    <p>固态分组，目的就是减少回溯次数， 使用(?&gt;…)括号中的匹配时如果产生了备选状态，那么一旦离开括号便会被立即 引擎抛弃掉。举个典型的例子如： ‘\w+:’这个表达式在进行匹配时的流程是这样的，会优先去匹配所有的符合\w的字符，假如字符串的末尾没有’:’，即匹配没有找到冒号，此时触发回溯机制，他会迫使前面的\w+释放字符，并且在交还的字符中重新尝试与’:’作比对。但是问题出现在这里: \w是不包含冒号的，显然无论如何都不会匹配成功，可是依照回溯机制，引擎还是得硬着头皮往前找，这就是对资源的浪费。所以我们就需要避免这种回溯，对此的方法就是将前面匹配到的内容固化，不令其存储备用状态！，那么引擎就会因为没有备用状态可用而只得结束匹配过程。大大减少回溯的次数。&nbsp;<br>如下代码，就不会进行回溯：</p>
                                    <pre name="code" class="prettyprint"><code class="hljs bash has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'nihaoaheloo';
<span class="hljs-variable">$pattern=<span class="hljs-string">'/(?&gt;\w+):/';
<span class="hljs-variable">$rs=preg_match(<span class="hljs-variable">$pattern, <span class="hljs-variable">$str);</span></span></span></span></span></span></span></code></pre>
                                    <p>当然有的时候，又需慎用固态分组，如下,我要检查$str中是否包含以a结尾的字符串，很明显是包含的，但是因为使用了固态分组，反而达不到我们想要的效果</p>
                                    <pre name="code" class="prettyprint"><code class="hljs ruby has-numbering"><span class="hljs-variable">$str=<span class="hljs-string">'nihaoahelaa';
<span class="hljs-variable">$pattern1=<span class="hljs-string">'/(?&gt;\w+)a/';
<span class="hljs-variable">$pattern2=<span class="hljs-string">'/\w+a/';
<span class="hljs-variable">$rs=preg_match(<span class="hljs-variable">$pattern1, <span class="hljs-variable">$str);<span class="hljs-regexp">//<span class="hljs-number">0
<span class="hljs-variable">$rs=preg_match(<span class="hljs-variable">$pattern2, <span class="hljs-variable">$str);<span class="hljs-regexp">//<span class="hljs-number">1</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
                                    <p>php中其他常用字符串操作函数</p>
                                    <ul>
                                        <li>字符串截取截取&nbsp;<br>string substr ( string&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-19-Frame" class="MathJax"><span id="MathJax-Span-639" class="math"><span id="MathJax-Span-640" class="mrow"><span id="MathJax-Span-641" class="mi">s<span id="MathJax-Span-642" class="mi">t<span id="MathJax-Span-643" class="mi">r<span id="MathJax-Span-644" class="mi">i<span id="MathJax-Span-645" class="mi">n<span id="MathJax-Span-646" class="mi">g<span id="MathJax-Span-647" class="mo">,<span id="MathJax-Span-648" class="mi">i<span id="MathJax-Span-649" class="mi">n<span id="MathJax-Span-650" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span>start [, int&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-20-Frame" class="MathJax"><span id="MathJax-Span-651" class="math"><span id="MathJax-Span-652" class="mrow"><span id="MathJax-Span-653" class="mi">l<span id="MathJax-Span-654" class="mi">e<span id="MathJax-Span-655" class="mi">n<span id="MathJax-Span-656" class="mi">g<span id="MathJax-Span-657" class="mi">t<span id="MathJax-Span-658" class="mi">h<span id="MathJax-Span-659" class="mo">]<span id="MathJax-Span-660" class="mo">)<span id="MathJax-Span-661" class="mi">s<span id="MathJax-Span-662" class="mi">t<span id="MathJax-Span-663" class="mi">r<span id="MathJax-Span-664" class="mi">i<span id="MathJax-Span-665" class="mi">n<span id="MathJax-Span-666" class="mi">g<span id="MathJax-Span-667" class="mi">m<span id="MathJax-Span-668" class="msubsup"><span id="MathJax-Span-669" class="mi">b<span id="MathJax-Span-670" class="mi">s<span id="MathJax-Span-671" class="mi">u<span id="MathJax-Span-672" class="mi">b<span id="MathJax-Span-673" class="mi">s<span id="MathJax-Span-674" class="mi">t<span id="MathJax-Span-675" class="mi">r<span id="MathJax-Span-676" class="mo">(<span id="MathJax-Span-677" class="mi">s<span id="MathJax-Span-678" class="mi">t<span id="MathJax-Span-679" class="mi">r<span id="MathJax-Span-680" class="mi">i<span id="MathJax-Span-681" class="mi">n<span id="MathJax-Span-682" class="mi">g</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>str , int&nbsp;<span class="MathJax_Preview"><span id="MathJax-Element-21-Frame" class="MathJax"><span id="MathJax-Span-683" class="math"><span id="MathJax-Span-684" class="mrow"><span id="MathJax-Span-685" class="mi">s<span id="MathJax-Span-686" class="mi">t<span id="MathJax-Span-687" class="mi">a<span id="MathJax-Span-688" class="mi">r<span id="MathJax-Span-689" class="mi">t<span id="MathJax-Span-690" class="mo">[<span id="MathJax-Span-691" class="mo">,<span id="MathJax-Span-692" class="mi">i<span id="MathJax-Span-693" class="mi">n<span id="MathJax-Span-694" class="mi">t</span></span></span></span></span></span></span></span></span></span></span></span>length = NULL [, string $encoding = mb_internal_encoding() ]] )</span></span></span></span></span></span></li>
                                        <li>字符串中大小写转换&nbsp;<br>strtoupper&nbsp;<br>strtolower&nbsp;<br>ucfirst&nbsp;<br>ucwords</li>
                                        <li>字符串比较&nbsp;<br>-strcmp、strcasecmp、strnatcmp</li>
                                        <li>字符串过滤</li>
                                        <li>字符串翻转&nbsp;<br>strrev($str);</li>
                                        <li>字符串随机排序&nbsp;<br>string str_shuffle ( string $str )</li>

                                    </ul>
                                    <h1 id="补充"><a name="t30"></a>补充</h1>
                                    <h2 id="怎样进行邮箱匹配url匹配手机匹配"><a name="t31"></a>怎样进行邮箱匹配，url匹配，手机匹配</h2>
                                    <p>使用preg_match函数进行匹配，以下内容从TP中复制而来。&nbsp;<br>邮箱验证&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-22-Frame" class="MathJax"><span id="MathJax-Span-695" class="math"><span id="MathJax-Span-696" class="mrow"><span id="MathJax-Span-697" class="mi">p<span id="MathJax-Span-698" class="mi">a<span id="MathJax-Span-699" class="mi">t<span id="MathJax-Span-700" class="mi">t<span id="MathJax-Span-701" class="mi">e<span id="MathJax-Span-702" class="mi">r<span id="MathJax-Span-703" class="mi">n<span id="MathJax-Span-704" class="msup"><span id="MathJax-Span-705" class="mo">=<span id="MathJax-Span-706" class="mo">′<span id="MathJax-Span-707" class="msubsup"><span id="MathJax-Span-708" class="texatom"><span id="MathJax-Span-709" class="mrow"><span id="MathJax-Span-710" class="mo">/<span id="MathJax-Span-711" class="mtext">\w<span id="MathJax-Span-712" class="mo">+<span id="MathJax-Span-713" class="mo">(<span id="MathJax-Span-714" class="mo">[<span id="MathJax-Span-715" class="mo">−<span id="MathJax-Span-716" class="mo">+<span id="MathJax-Span-717" class="mo">.<span id="MathJax-Span-718" class="mo">]<span id="MathJax-Span-719" class="mtext">\w<span id="MathJax-Span-720" class="mo">+<span id="MathJax-Span-721" class="mo">)<span id="MathJax-Span-722" class="mo">∗<span id="MathJax-Span-723" class="texatom"><span id="MathJax-Span-724" class="mrow"><span id="MathJax-Span-725" class="mo">@<span id="MathJax-Span-726" class="mtext">\w<span id="MathJax-Span-727" class="mo">+<span id="MathJax-Span-728" class="mo">(<span id="MathJax-Span-729" class="mo">[<span id="MathJax-Span-730" class="mo">−<span id="MathJax-Span-731" class="mo">.<span id="MathJax-Span-732" class="mo">]<span id="MathJax-Span-733" class="mtext">\w<span id="MathJax-Span-734" class="mo">+<span id="MathJax-Span-735" class="mo">)<span id="MathJax-Span-736" class="mo">∗<span id="MathJax-Span-737" class="mtext">\.<span id="MathJax-Span-738" class="mtext">\w<span id="MathJax-Span-739" class="mo">+<span id="MathJax-Span-740" class="mo">(<span id="MathJax-Span-741" class="mo">[<span id="MathJax-Span-742" class="mo">−<span id="MathJax-Span-743" class="mo">.<span id="MathJax-Span-744" class="mo">]<span id="MathJax-Span-745" class="mtext">\w<span id="MathJax-Span-746" class="mo">+<span id="MathJax-Span-747" class="mo">)<span id="MathJax-Span-748" class="mo">∗</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>/’;&nbsp;<br>url匹配&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-23-Frame" class="MathJax"><span id="MathJax-Span-749" class="math"><span id="MathJax-Span-750" class="noError">pattern='/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&amp;~`@[\]\':+!\.#\w]*)?/’;&nbsp;<br>手机验证&nbsp;<br><span class="MathJax_Preview"><span id="MathJax-Element-24-Frame" class="MathJax"><span id="MathJax-Span-751" class="math"><span id="MathJax-Span-752" class="mrow"><span id="MathJax-Span-753" class="mi">p<span id="MathJax-Span-754" class="mi">a<span id="MathJax-Span-755" class="mi">t<span id="MathJax-Span-756" class="mi">t<span id="MathJax-Span-757" class="mi">e<span id="MathJax-Span-758" class="mi">r<span id="MathJax-Span-759" class="mi">n<span id="MathJax-Span-760" class="msup"><span id="MathJax-Span-761" class="mo">=<span id="MathJax-Span-762" class="mo">′<span id="MathJax-Span-763" class="msubsup"><span id="MathJax-Span-764" class="texatom"><span id="MathJax-Span-765" class="mrow"><span id="MathJax-Span-766" class="mo">/<span id="MathJax-Span-767" class="mn">1<span id="MathJax-Span-768" class="mo">[<span id="MathJax-Span-769" class="mn">3458<span id="MathJax-Span-770" class="mo">]<span id="MathJax-Span-771" class="mtext">\d<span id="MathJax-Span-772" class="texatom"><span id="MathJax-Span-773" class="mrow"><span id="MathJax-Span-774" class="mn">10</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>/’;</span></span></span></span></span></span></span></span></p>
                                    <h2 id="php中正则的优缺点"><a name="t32"></a>php中正则的优缺点</h2>
                                    <p>php中正则在某些时候，能帮我们解决php函数很多困难的匹配或是替换。然后php中正则的效率，往往是我们需要考虑的，所以在某些时候，能不用正则还是尽量不去用它，除非，某些场合必须用到，或是我们能够有效减少其回溯次数。</p></div><div id="MySignature"></div>
                                <div class="clear"></div>
                                <div id="blog_post_info_block">
                                    <div id="BlogPostCategory"></div>
                                    <div id="EntryTag"></div>
                                    <div id="blog_post_info"><div id="green_channel">
                                        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(5718319,cb_blogId,1);green_channel_success(this,'谢谢推荐！');">好文要顶</a>
                                        <a id="green_channel_follow" onclick="follow('985de844-ca18-e611-9fc1-ac853d9f53cc');" href="javascript:void(0);">关注我</a>
                                        <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
                                        <a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="//common.cnblogs.com/images/icon_weibo_24.png" alt=""></a>
                                        <a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="//common.cnblogs.com/images/wechat.png" alt=""></a>
                                    </div>
                                        <div id="author_profile">
                                            <div id="author_profile_info" class="author_profile_info">
                                                <a href="http://home.cnblogs.com/u/hellohell/" target="_blank"><img src="//pic.cnblogs.com/face/955709/20160801134006.png" class="author_avatar" alt=""></a>
                                                <div id="author_profile_detail" class="author_profile_info">
                                                    <a href="http://home.cnblogs.com/u/hellohell/">helloworldlee</a><br>
                                                    <a href="http://home.cnblogs.com/u/hellohell/followees">关注 - 2</a><br>
                                                    <a href="http://home.cnblogs.com/u/hellohell/followers">粉丝 - 5</a>
                                                </div>
                                            </div>
                                            <div class="clear"></div>
                                            <div id="author_profile_honor"></div>
                                            <div id="author_profile_follow">
                                                <a href="javascript:void(0);" onclick="follow('985de844-ca18-e611-9fc1-ac853d9f53cc');return false;">+加关注</a>
                                            </div>
                                        </div>
                                        <div id="div_digg">
                                            <div class="diggit" onclick="votePost(5718319,'Digg')">
                                                <span class="diggnum" id="digg_count">2</span>
                                            </div>
                                            <div class="buryit" onclick="votePost(5718319,'Bury')">
                                                <span class="burynum" id="bury_count">1</span>
                                            </div>
                                            <div class="clear"></div>
                                            <div class="diggword" id="digg_tips">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="clear"></div>
                                    <div id="post_next_prev"><a href="http://www.cnblogs.com/hellohell/p/5718252.html" class="p_n_p_prefix">« </a> 上一篇：<a href="http://www.cnblogs.com/hellohell/p/5718252.html" title="发布于2016-07-29 14:25">MySQL的Query Cache原理分析</a><br><a href="http://www.cnblogs.com/hellohell/p/5718345.html" class="p_n_p_prefix">» </a> 下一篇：<a href="http://www.cnblogs.com/hellohell/p/5718345.html" title="发布于2016-07-29 14:44">二叉树相关面试题</a><br></div>
                                </div>


                            </div>
                            <div class="postDesc">posted @ <span id="post-date">2016-07-29 14:38</span> <a href="http://www.cnblogs.com/hellohell/">helloworldlee</a> 阅读(<span id="post_view_count">32015</span>) 评论(<span id="post_comment_count">1</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=5718319" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(5718319);return false;">收藏</a></div>
                        </div>
                        <script type="text/javascript">var allowComments=true,cb_blogId=285161,cb_entryId=5718319,cb_blogApp=currentBlogApp,cb_blogUserGuid='985de844-ca18-e611-9fc1-ac853d9f53cc',cb_entryCreatedDate='2016/7/29 14:38:00';loadViewCount(cb_entryId);</script>

                    </div><!--end: topics 文章、评论容器-->
                </div><a name="!comments"></a><div id="blog-comments-placeholder"><div id="comments_pager_top"></div>
                <br>
                <div class="feedback_area_title">评论列表</div>
                <div class="feedbackNoItems"></div>

                <div class="feedbackItem">
                    <div class="feedbackListSubtitle">
                        <div class="feedbackManage">
                            &nbsp;&nbsp;<span class="comment_actions"></span>
                        </div>
                        <a href="#3712788" class="layer">#1楼</a><a name="3712788" id="comment_anchor_3712788"></a><span id="comment-maxId" style="display:none;">3712788</span><span id="comment-maxDate" style="display:none;">2017/6/12 19:16:31</span>  <span class="comment_date">2017-06-12 19:16</span> <a id="a_comment_author_3712788" href="http://www.cnblogs.com/hll1688/" target="_blank">阿木木ll</a> <a href="http://msg.cnblogs.com/send/%E9%98%BF%E6%9C%A8%E6%9C%A8ll" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
                    </div>
                    <div class="feedbackCon">
                        <div id="comment_body_3712788" class="blog_comment_body">手机验证怕是有问题啊，<br> "/^1[34578]\d{9}$/";</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3712788,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3712788,'Bury',this)">反对(0)</a></div><span id="comment_3712788_avatar" style="display:none;">http://pic.cnblogs.com/face/880283/20161015222705.png</span>
                    </div>
                </div>
                <div id="comments_pager_bottom"></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
                <div id="comment_form" class="commentform">
                    <a name="commentform"></a>
                    <div id="divCommentShow"></div>
                    <div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="#" onclick="return RefreshPage();">刷新页面</a><a href="#top">返回顶部</a></div>
                    <div id="comment_form_container"><div class="login_tips">注册用户登录后才能发表评论，请 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return login('commentform');">登录</a> 或 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return register();">注册</a>，<a href="http://www.cnblogs.com">访问</a>网站首页。</div></div>
                    <div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
                    <div id="ad_t2"></div>
                    <div id="opt_under_post"></div>
                    <div id="cnblogs_c1" class="c_ad_block"></div>
                    <div id="under_post_news"><div class="itnews c_ad_block"><b>最新IT新闻</b>:<br> ·  <a href="http://news.cnblogs.com/n/572569/" target="_blank">王思聪被讨薪续：熊猫官方表示从未违约 前员工称主播狼心狗肺</a><br> ·  <a href="http://news.cnblogs.com/n/572568/" target="_blank">亚马逊升级Echo软件 现在智能音箱能当对讲机使用啦</a><br> ·  <a href="http://news.cnblogs.com/n/572567/" target="_blank">FB、微软、YouTube和Twitter四巨头联手反恐</a><br> ·  <a href="http://news.cnblogs.com/n/572566/" target="_blank">身处激烈竞争的芯片市场，英伟达如何让股价一年翻了4倍？</a><br> ·  <a href="http://news.cnblogs.com/n/572565/" target="_blank">Google精英黑客团队Project Zero：守护全世界的安全</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="_blank">更多新闻...</a></div></div>
                    <div id="cnblogs_c2" class="c_ad_block"></div>
                    <div id="under_post_kb"><div class="itnews c_ad_block" id="kb_block"><b>最新知识库文章</b>:<br><div id="kb_recent"> ·  <a href="http://kb.cnblogs.com/page/570194/" target="_blank">小printf的故事：什么是真正的程序员？</a><br> ·  <a href="http://kb.cnblogs.com/page/569992/" target="_blank">程序员的工作、学习与绩效</a><br> ·  <a href="http://kb.cnblogs.com/page/569056/" target="_blank">软件开发为什么很难</a><br> ·  <a href="http://kb.cnblogs.com/page/565901/" target="_blank">唱吧DevOps的落地，微服务CI/CD的范本技术解读</a><br> ·  <a href="http://kb.cnblogs.com/page/566523/" target="_blank">程序员，如何从平庸走向理想？</a><br></div>» <a href="http://kb.cnblogs.com/" target="_blank">更多知识库文章...</a></div></div>
                    <div id="HistoryToday" class="c_ad_block"></div>
                    <script type="text/javascript">
                        fixPostBody();
                        setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
                        deliverAdT2();
                        deliverAdC1();
                        deliverAdC2();
                        loadNewsAndKb();
                        loadBlogSignature();
                        LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
                        GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate);
                        loadOptUnderPost();
                        GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);
                    </script>
                </div>


            </div><!--end: forFlow -->
        </div><!--end: mainContent 主体内容容器-->

        <div id="sideBar">
            <div id="sideBarMain">

                <!--done-->
                <div class="newsItem">
                    <h3 class="catListTitle">公告</h3>
                    <div id="blog-news"><div id="profile_block">昵称：<a href="http://home.cnblogs.com/u/hellohell/">helloworldlee</a><br>园龄：<a href="http://home.cnblogs.com/u/hellohell/" title="入园时间：2016-05-13">1年1个月</a><br>粉丝：<a href="http://home.cnblogs.com/u/hellohell/followers/">5</a><br>关注：<a href="http://home.cnblogs.com/u/hellohell/followees/">2</a><div id="p_b_follow"><a href="javascript:void(0);" onclick="follow('985de844-ca18-e611-9fc1-ac853d9f53cc')">+加关注</a></div></div></div><script type="text/javascript">loadBlogNews();</script>
                </div>

                <div id="blog-calendar"><table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="日历">
                    <tbody><tr><td colspan="7"><table class="CalTitle" cellspacing="0">
                        <tbody><tr><td class="CalNextPrev"><a href="javascript:void(0);" onclick="loadBlogCalendar('2017/05/01');return false;">&lt;</a></td><td align="center">2017年6月</td><td class="CalNextPrev" align="right"><a href="javascript:void(0);" onclick="loadBlogCalendar('2017/07/01');return false;">&gt;</a></td></tr>
                        </tbody></table></td></tr><tr><th class="CalDayHeader" align="center" abbr="日" scope="col">日</th><th class="CalDayHeader" align="center" abbr="一" scope="col">一</th><th class="CalDayHeader" align="center" abbr="二" scope="col">二</th><th class="CalDayHeader" align="center" abbr="三" scope="col">三</th><th class="CalDayHeader" align="center" abbr="四" scope="col">四</th><th class="CalDayHeader" align="center" abbr="五" scope="col">五</th><th class="CalDayHeader" align="center" abbr="六" scope="col">六</th></tr><tr><td class="CalOtherMonthDay" align="center">28</td><td class="CalOtherMonthDay" align="center">29</td><td class="CalOtherMonthDay" align="center">30</td><td class="CalOtherMonthDay" align="center">31</td><td align="center">1</td><td align="center">2</td><td class="CalWeekendDay" align="center">3</td></tr><tr><td class="CalWeekendDay" align="center">4</td><td align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">9</td><td class="CalWeekendDay" align="center">10</td></tr><tr><td class="CalWeekendDay" align="center">11</td><td align="center">12</td><td align="center">13</td><td align="center">14</td><td align="center">15</td><td align="center">16</td><td class="CalWeekendDay" align="center">17</td></tr><tr><td class="CalWeekendDay" align="center">18</td><td align="center">19</td><td align="center">20</td><td align="center">21</td><td align="center"><a href="http://www.cnblogs.com/hellohell/archive/2017/06/22.html"><u>22</u></a></td><td align="center">23</td><td class="CalWeekendDay" align="center">24</td></tr><tr><td class="CalWeekendDay" align="center">25</td><td align="center">26</td><td class="CalTodayDay" align="center">27</td><td align="center">28</td><td align="center">29</td><td align="center">30</td><td class="CalOtherMonthDay" align="center">1</td></tr><tr><td class="CalOtherMonthDay" align="center">2</td><td class="CalOtherMonthDay" align="center">3</td><td class="CalOtherMonthDay" align="center">4</td><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td><td class="CalOtherMonthDay" align="center">7</td><td class="CalOtherMonthDay" align="center">8</td></tr>
                    </tbody></table></div><script type="text/javascript">loadBlogDefaultCalendar();</script>

                <div id="leftcontentcontainer">
                    <div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
                        <div id="sidebar_search" class="mySearch">
                            <h3 class="catListTitle">搜索</h3>
                            <div id="sidebar_search_box">
                                <div id="widget_my_zzk" class="div_my_zzk"><input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="找找看" id="btnZzk" class="btn_my_zzk"></div>
                                <div id="widget_my_google" class="div_my_zzk"><input type="text" name="google_q" id="google_q" onkeydown="return google_go_enter(event)" class="input_my_zzk">&nbsp;<input onclick="google_go()" type="button" value="谷歌搜索" class="btn_my_zzk"></div>
                            </div>
                        </div>

                    </div><div id="sidebar_shortcut" class="sidebar-block">
                        <div class="catListLink">
                            <h3 class="catListTitle">常用链接</h3>
                            <ul>
                                <li><a href="http://www.cnblogs.com/hellohell/p/" title="我的博客的随笔列表">我的随笔</a></li><li><a href="http://www.cnblogs.com/hellohell/MyComments.html" title="我发表过的评论列表">我的评论</a></li><li><a href="http://www.cnblogs.com/hellohell/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li><li><a href="http://www.cnblogs.com/hellohell/RecentComments.html" title="我的博客的评论列表">最新评论</a></li><li><a href="http://www.cnblogs.com/hellohell/tag/" title="我的博客的标签列表">我的标签</a></li>
                            </ul>
                            <div id="itemListLin_con" style="display:none;">
                                <ul>

                                </ul>
                            </div>
                        </div></div><div id="sidebar_toptags" class="sidebar-block"></div><div id="sidebar_categories">
                        <div id="sidebar_postarchive" class="catListPostArchive sidebar-block">
                            <h3 class="catListTitle">随笔档案</h3>

                            <ul>

                                <li><a id="CatList_LinkList_0_Link_0" href="http://www.cnblogs.com/hellohell/archive/2017/06.html">2017年6月 (1)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_1" href="http://www.cnblogs.com/hellohell/archive/2017/03.html">2017年3月 (2)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_2" href="http://www.cnblogs.com/hellohell/archive/2017/02.html">2017年2月 (3)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_3" href="http://www.cnblogs.com/hellohell/archive/2017/01.html">2017年1月 (1)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_4" href="http://www.cnblogs.com/hellohell/archive/2016/12.html">2016年12月 (5)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_5" href="http://www.cnblogs.com/hellohell/archive/2016/11.html">2016年11月 (2)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_6" href="http://www.cnblogs.com/hellohell/archive/2016/10.html">2016年10月 (2)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_7" href="http://www.cnblogs.com/hellohell/archive/2016/09.html">2016年9月 (1)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_8" href="http://www.cnblogs.com/hellohell/archive/2016/08.html">2016年8月 (9)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_9" href="http://www.cnblogs.com/hellohell/archive/2016/07.html">2016年7月 (8)</a> </li>

                                <li><a id="CatList_LinkList_0_Link_10" href="http://www.cnblogs.com/hellohell/archive/2016/06.html">2016年6月 (5)</a> </li>

                            </ul>

                        </div>

                    </div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap">
                        <div class="catListComment">
                            <h3 class="catListTitle">最新评论</h3>

                            <div id="RecentCommentsBlock"><ul>
                                <li class="recent_comment_title"><a href="http://www.cnblogs.com/hellohell/p/5718319.html#3712788">1. Re:php中正则表达式详解</a></li>
                                <li class="recent_comment_body">手机验证怕是有问题啊，<br> "/^1[34578]\d{9}$/";</li>
                                <li class="recent_comment_author">--阿木木ll</li>
                            </ul>
                            </div>
                        </div>
                    </div></div><div id="sidebar_topviewedposts" class="sidebar-block"><div id="topview_posts_wrap">
                        <div class="catListView">
                            <h3 class="catListTitle">阅读排行榜</h3>
                            <div id="TopViewPostsBlock"><ul><li><a href="http://www.cnblogs.com/hellohell/p/5718319.html">1. php中正则表达式详解(32012)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5718175.html">2. PHP实现各种经典算法(7060)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5718205.html">3. php通过Mysqli和PDO连接mysql数据详解(4593)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5718238.html">4. MySQL查询优化器工作原理解析(1598)</a></li><li><a href="http://www.cnblogs.com/hellohell/p/5733712.html">5. PHPDocument 代码注释规范总结(444)</a></li></ul></div>
                        </div>
                    </div></div><div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap">
                        <div class="catListFeedback">
                            <h3 class="catListTitle">评论排行榜</h3>
                            <div id="TopFeedbackPostsBlock"><ul><li><a href="http://www.cnblogs.com/hellohell/p/5718319.html">1. php中正则表达式详解(1)</a></li></ul></div>
                        </div>
                    </div></div><div id="sidebar_topdiggedposts" class="sidebar-block"><div id="topdigg_posts_wrap">
                        <div class="catListView">
                            <h3 class="catListTitle">推荐排行榜</h3>
                            <div id="TopDiggPostsBlock"><ul><li><a href="http://www.cnblogs.com/hellohell/p/5718319.html">1. php中正则表达式详解(2)</a></li></ul></div>
                        </div></div></div></div><script type="text/javascript">loadBlogSideColumn();</script>
                </div>

            </div><!--end: sideBarMain -->
        </div><!--end: sideBar 侧边栏容器 -->
        <div class="clear"></div>
    </div><!--end: main -->
    <div class="clear"></div>
    <div id="footer">

        <!--done-->
        Copyright ©2017 helloworldlee
    </div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->


<audio controls="controls" style="display: none;"></audio></body><style type="text/css">#yddContainer{display:block;font-family:Microsoft YaHei;position:relative;width:100%;height:100%;top:-4px;left:-4px;font-size:12px;border:1px solid}#yddTop{display:block;height:22px}#yddTopBorderlr{display:block;position:static;height:17px;padding:2px 28px;line-height:17px;font-size:12px;color:#5079bb;font-weight:bold;border-style:none solid;border-width:1px}#yddTopBorderlr .ydd-sp{position:absolute;top:2px;height:0;overflow:hidden}.ydd-icon{left:5px;width:17px;padding:0px 0px 0px 0px;padding-top:17px;background-position:-16px -44px}.ydd-close{right:5px;width:16px;padding-top:16px;background-position:left -44px}#yddKeyTitle{float:left;text-decoration:none}#yddMiddle{display:block;margin-bottom:10px}.ydd-tabs{display:block;margin:5px 0;padding:0 5px;height:18px;border-bottom:1px solid}.ydd-tab{display:block;float:left;height:18px;margin:0 5px -1px 0;padding:0 4px;line-height:18px;border:1px solid;border-bottom:none}.ydd-trans-container{display:block;line-height:160%}.ydd-trans-container a{text-decoration:none;}#yddBottom{position:absolute;bottom:0;left:0;width:100%;height:22px;line-height:22px;overflow:hidden;background-position:left -22px}.ydd-padding010{padding:0 10px}#yddWrapper{color:#252525;z-index:10001;background:url(chrome-extension://eopjamdnofihpioajgfdikhhbobonhbb/ab20.png);}#yddContainer{background:#fff;border-color:#4b7598}#yddTopBorderlr{border-color:#f0f8fc}#yddWrapper .ydd-sp{background-image:url(chrome-extension://eopjamdnofihpioajgfdikhhbobonhbb/ydd-sprite.png)}#yddWrapper a,#yddWrapper a:hover,#yddWrapper a:visited{color:#50799b}#yddWrapper .ydd-tabs{color:#959595}.ydd-tabs,.ydd-tab{background:#fff;border-color:#d5e7f3}#yddBottom{color:#363636}#yddWrapper{min-width:250px;max-width:400px;}</style></html>